Hi there, I would like to ask a question about how to pass a variable from page to page. For example, I have my first page for login and used a session with cookie and after submitting successfully and redirect my page to another page I want show statement like Hello Smith or Welcome Smith, and it doesn't work properly. Anyone knows the soulution would be appreciated. Thanks
This is the code for the second page that I want the name of the user to show up.
So what's wrong with my code. Thanks again
Code:
<?php
if (loggedin())
{
header("Location: redirectpage.php");
exit();
}
if ($_POST["login"])
{
global $username;
$username = $_POST['username'];
$password = $_POST['password'];
$rememberme = $_POST['rememberme'];
if($username&&$password)
{
$login = mysql_query("SELECT * FROM usersystem where username='$username'");
while ($row = mysql_fetch_assoc($login))
{
$db_password = $row['password'];
if($password==$db_password)
else
setcookie("username", $username, time()+7200);
else if ($rememberme=="")
$_SESSION['logged_in']== $username;
$_SESSION['username'] =$_POST['username'];
//userarea.php
header("Location: redirectpage.php");
exit();
}
}
}
else
die("Please enter a username and password");
}
?>
Code:
<?php session_start(); $username = $_SESSION['username']; echo $_SESSION['username']; echo "Hello ". $username ; ?>
Comment