HY!
i have an issue in php session. the issue is that the session work fine in index page but the username can't show in other pages.
lohin.php code
<?php session_start();
include './header.php';
include 'connection.php';
if(isset($_POST) && count($_POST)>0) {
$user = $_POST['username'];
$pass = $_POST['password'];
$sSQL = "SELECT * FROM ulog WHERE User_Name ='".$user."' AND Password = '".$pass."'";
$result = mysql_query($sSQL) or die(mysql_error());
$row=mysql_num_rows($result);
if($row==1)
{
// Set username session variable
$_SESSION['username'] = $_POST['username'];
// Jump to secured page
header('Location:index.php');
}
}
else
{
header("location:login.html");
}
?>
index.php code
<?php session_start();
include './header.php';
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username']))
{
header('Location:login.html');
}
?>
<div id="welcome">
<h4> Welcome <?php echo $_SESSION['username']; ?> <a href="logout.php">Logout</h4></a></p>
</div>
<div id="content">
<p>Learn to Design and Develop Website.<br />
Learn Programing From Tutorial's teaches you the fundamentals of web development and not just programming. You will learn how to create amazing websites through programming and design tutorials. The web development tutorials on your left are designed for you to move through them in order to have an overall understanding of web design and development.</p>
</div>
<?php include './footer.php'; ?>
the code i use in other pages which is not working is..
<?php session_start();
include 'login.php';
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username']))
{
header('Location:login.html');
}
?>
the above code is used in other pages but it is not working..
what type of code i need to access username in all pages..