I'm using the same header.php and footer.php for php files on the backend of a CMS so when a user wants to login, they'll a part of that header.php that I don't want them to see as it's part of the backend e.g.
<section id="sidebar">
<p>Not to be seen</p>
</section>
<section id="content">
<p>Login here</p>
</section>
Is there a PHP function that if a user is logged in, can see the #sidebar and those who are not logged in will remove it. Using display: none; is pointless as it still visible if somebody was to remove that CSS style.
Update:
I found out how to do it. The function was
<?php if(($user = Users::authed()) !== false): ?>
<section id="sidebar">
<p>Not to be seen</p>
</section>
<?php endif; ?>
<section id="content">
<p>Login here</p>
</section>
Thanks to those who answered!
The answer depends on how you login the user i.e. using cookies or sessions or something else.
The basic workflow will however be
if(user_logged_in())
echo "<section id=\"sidebar\">
<p>Not to be seen</p>
</section>";
you must have to try this scenario with native session i hope it will work for you
if(isset($_SESSION['username'])){
<section id="sidebar">
<p>Not to be seen</p>
</section>
}else{
<section id="content">
<p>Login here</p>
</section>
}
The very simplest form.
Once logged in populate session variable like $_SESSION["UserID"] with some user id or username
Modify your code like follows:
<section id="sidebar">
<p>Not to be seen</p>
</section>
<?php
if ($_SESSION["UserID"]) {
?>
<section id="content">
<p>Login here</p>
</section>
<?php
}
?>
Related
I am Developing a code using php . In which I am importing two files (header.php and footer.php) in another php file index.php.
Now I want that header.php and footer.php should be fixed while scrolling horizontally. can you suggest me the code. I am using the following code
Header.php
code here
footer.php
code here
index.php
<?php include("header.php"); ?>
welcome to index file
welcome to index file
welcome to index file
<?php include("footer.php"); ?>
In this file index.php, I want that header and footer should be fixed while scrolling horizontally and others css should also not be disturbed.
try this.,
<div id="header">
<?PHP include_once('header.php');?>
</div>
<div id="wrap">
welcome to index file
</div>
<div id="footer">
<?PHP include_once('foo.php');?>
</div>
css:
#header{position:fixed;top:0px;}
#footer{position:fixed;bottom:0px;}
or
header.php
<div id ="header"></div><div id="content">
footer.php
</div><div id="footer"></div>
index.php
<?PHP include_once('header.php');?>
content here.,
<?PHP include_once('footer.php');?>
Your solucion is ok.
only i recomend use something like this:
<div id="header">
<?PHP include_once('header.php');?>
</div>
<div id="wrap">
here is my html content
</div>
<div id="footer">
<?PHP include_once('foo.php');?>
</div>
the use of include_once is for not repeat the include of some file
and with a good css obtains a excelent layout
use HTML5 and use include_once
<header>
<?PHP include_once('header.php');?>
</header>
<div id="wrap">
here is my html content
</div>
<footer>
<?PHP include_once('foo.php');?>
</footer>
Here is just a sample FIDDLE DEMO
html,body{
margin:0;padding:0;
}
header{
background:Green;
height:50px;
}
footer{
position:absolute;
width:100%;
bottom:0;
background:Red;
height:50px;
}
In your css, just put the following attribute:
position:fixed; and that should do the trick.
I have a multipage and work on mobile, I use PHP session to keep to consistence, I added a logout button on top and session should be cleared and reload the login page. Below is the content of page, login page is redirected after clicking the logout button but session id seem doesn't be cleared. I have already load the logout with data-ajax=false
HTML
<body class="ui-mobile-viewport ui-overlay-a">
<section id="home" data-role="page">
<header data-role="header">
<h1>Summary</h1>
</header>
<article data-role="content" class="ui-content" role="main">
<button href="#signin_section">Sign-in</button><br>
</article> <!-- article content -->
</section> <!-- section home -->
<section id="signin_section" data-role="page">
<header data-role="header">
<h1>Summary</h1>
Logout
</header>
<article data-role="content" class="ui-content" role="main">
<div id="signin">
<form action="checklogin.php" name="form" id="form" method="post">
... (content omitted) ...
</form>
</div>
</article>
</section>
</body>
PHP script of Logout
<?php
session_start();
unset($_SESSION['login']);
session_destroy();
header("Location: http://jetsodev.aimedia.hk/admincheck");
?>
PHP script of Login
<?php
session_start();
if (isset($_SESSION['login'])) {
....
}
?>
You should use session_unset rather than session_destroy, since the latter “does not unset any of the global variables associated with the session, or unset the session cookie.”
I have simple slideshow on my home page as a php include. It shows up, but it seems to be floating up to the top of the page, and not falling in line with all of the other includes, ie, header, menu, etc. In addition, the image isn't lined up with the arrows. Here is where it lives:
http://www.starhilldesignstudio.com/adventure-suites/index-test.php
And here is the slideshow solo (arrows line up):
http://www.starhilldesignstudio.com/adventure-suites/slideshow-home.php
My html code:
<div id="container">
<div id="header">
<?php include 'menu.php'; ?>
</div>
<div id="mainContent" style="position:relative; z-index:1;">
<div class="center margin-top "><?php include 'slideshow-home.php'; ?></div>
<?php include 'home-blurb.php'; ?>
<?php include 'home-list.php'; ?>
<?php include 'bottom-stripe.php'; ?>
<div id="footer2">
<?php include 'footer.php'; ?>
</div>
</div>
</div>
THANKS!!!
Looks like a misplaced include, place your include function where you wanted to put your file to.
Example you wanted to put it before your content in between your header and footer:
include "header.php"
include "slider.php"
include "content.php"
include "footer.php"
Let us know if this is not the case.
<div id="container">
<div id="header">
<?php include 'menu.php'; ?>
</div>
<div id="mainContent" style="position:relative; z-index:1;">
<!-- Add this... -->
<div style="clear:both;padding-bottom:10px"></div>
<!--<div class="clear"></div>consider making the above style into a class.-->
<div class="center margin-top "><?php include 'slideshow-home.php'; ?></div>
<?php include 'home-blurb.php'; ?>
<?php include 'home-list.php'; ?>
<?php include 'bottom-stripe.php'; ?>
<div id="footer2">
<?php include 'footer.php'; ?>
</div>
</div>
</div>
I have a php page that has many includes. The whole page runs fine, but for my navigation bar, it does not open any page when I click on it. Please, what is missing here. Any help will be appreciated. many thanks
Here are my codes for the includes
<div id='cssmenu'>
<ul>
<li class='active'><span>Home</span></li>
<li><span>About Us</span></li>
<li><span>Packages</span></li>
<li><span>Partners</span></li>
<li><span>Gallery</span></li>
<li class='last'><span>Contact Us</span></li>
</ul>
</div>
And here is my main page code:
<body>
<div id="wrapper">
<div>
<img src="images/banner.png" width="940" height="200" />
</div>
<?php include('includes/nav.php'); ?>
<?php include('includes/slider.php'); ?>
<?php include('includes/nav.php'); ?>
<?php include('includes/contents.php'); ?>
<?php include('includes/sidebar.php'); ?>
<?php include('includes/footer.php'); ?>
</div> <!-- End #wrapper -->
</body>
Not sure of your file structure, but try removing the '../' on all you links
Change this:
<li class='active'><span>Home</span></li>
to this:
<li class='active'><span>Home</span></li>
Take the ../ out of your path.
When you include the nav.htm to your main page it acts as if it is in the main folder
Therefore if you use '../' it won't find it.
I am using Bootstrap but under the roots.io wordpress template using a 'wrapperless theme'
i am trying to achieve this http://roots.io/ - where there are sections of colour but the page content itself isn't full width.
the answer I have been given is to make the container class 100% - but this just makes all the content full width.
Im really stuck and ive been trying to figure this out for hours. - I know that sounds noobish and it is, but I can't get past this point.
all the page templates take their its style from base.php, code here
<?php get_template_part('templates/head'); ?>
<body <?php body_class(); ?>>
<!--[if lt IE 8]><div class="alert alert-warning"><?php _e('You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.', 'roots'); ?></div><![endif]-->
<?php
do_action('get_header');
// Use Bootstrap's navbar if enabled in config.php
if (current_theme_supports('bootstrap-top-navbar')) {
get_template_part('templates/header-top-navbar');
} else {
get_template_part('templates/header');
}
?>
<div class="wrap container" role="document">
<div class="content row">
<div class="main <?php echo roots_main_class(); ?>" role="main">
<?php include roots_template_path(); ?>
</div><!-- /.main -->
<?php if (roots_display_sidebar()) : ?>
<aside class="sidebar <?php echo roots_sidebar_class(); ?>" role="complementary">
<?php include roots_sidebar_path(); ?>
</aside><!-- /.sidebar -->
<?php endif; ?>
</div><!-- /.content -->
</div><!-- /.wrap -->
<?php get_template_part('templates/footer'); ?>
</body>
</html>
so Im just not sure how to get past it in any of the page templates
About the first part of your question: "100% width colored parts".
Cause Bootstrap use the box-sizing: border-box model every html-element gets 100% width of its parent by default. So wrap your .container div's in other element (div, header, etc). This wrapper is a direct child of the body and gets 100% width. See: http://bootply.com/87196
<header role="banner" class="banner">
<div class="container" style="background-color:red;">
Header example
</div>
</header>
<div style="background-color:blue;">Elements get 100% width by default</div>
The second part about your page templates. The code you show use the get_template_part(). This function is a core function of WordPress. See http://codex.wordpress.org/Function_Reference/get_template_part#Using_loop.php_in_child_themes. You will find where your templates should be located.
But i think read http://roots.io/roots-101/#theme-templates first.
Thank you, I had a few solutions offered to me yesterday also, in case anyone else looks at this.
my own was simply to remove the .container class from the base.php file. - this just stopped the content of every page being constrained in a container by default. - this way I was able to add sections to the page at full browser width, and add .container inside them to constrain the actual content.
lines 16 and 17 of original base.php
<div class="wrap <?php if ( ! is_front_page() ): ?>container<?php endif; ?>" role="document">
<div class="content <?php if ( ! is_front_page() ): ?>row<?php endif; ?>">
In app.less
.home .main {
padding: 0;
}
Then add your sections like so:
<section class="semantic-section-class">
<div class="container">
<!-- your content -->
</div>
</section>