Created
March 7, 2017 13:34
-
-
Save Mauryashubham/f60a519275863587c0db4964b62ad61e to your computer and use it in GitHub Desktop.
How to use Sessions in Menu Bar after Login in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="navbar navbar-inverse" style="border-radius: 0px;"> | |
<div class="container-fluid"> | |
<div class="navbar-header"> | |
<a class="navbar-brand" href="#">Your WebSite Name</a> | |
</div> | |
<ul class="nav navbar-nav"> | |
<li class="active"><a href="#">Home</a></li> | |
<li><a href="#">About</a></li> | |
</ul> | |
<ul class="nav navbar-nav navbar-right"> | |
<?php if(!$_SESSION['admin']) {?> | |
<li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li> | |
<?php } else { ?> | |
<li><a href="#">Welcome, <?php echo $_SESSION['admin'];?></a></li> | |
<?php } ?> | |
</ul> | |
</div> | |
</nav> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
session_start(); | |
//error_reporting(0); | |
if(isset($_POST['login'])) | |
{ | |
$name=$_POST['name']; | |
$pass=$_POST['pass']; | |
if($name=="admin" & $pass=="admin") | |
{ | |
$_SESSION['admin']=$name; | |
//echo "Welcome, ".$_SESSION['admin']; | |
header("location:welcome.php"); | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Bootstrap Case</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<?php @include 'header.php' ?> | |
<form method="post"> | |
<input type="text" placeholder="Enter Username" name="name" required> | |
<input type="password" placeholder="Enter Password" name="pass" required> | |
<button type="submit" name="login">Login</button> | |
</form> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
session_start(); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> | |
</head> | |
<body> | |
<?php @include 'header.php' ?> | |
welcome | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment