Here you set username in session
PHP Code:
<?php
//start session
session_start();
// connect to the mysql server
$conn = @mysql_connect("localhost","user","pass")
or die ("Could not connect to mysql table");
// select the database
$rs=@mysql_select_db("db",$conn)
or die ("Could not select database");
//create query
$sql="select * from tblUsers where username='$username' and
password='$password'";
$rs=mysql_query($sql,$conn) or die(mysql_error());
if($rs && mysql_num_rows($rs))
{
$_SESSION['username'] = $username;
header('Refresh: 1; URL="disp_info.php"');
}
else
{
echo "Combination Username/Password is incorrect. Re-enter!";
$log=false;
}
?>
On this page you retrieve username
PHP Code:
session_start();
if(isset($_SESSION['username']))
{
$username = $_SESSION['username'];
echo $username;
}
else
{
echo "You are not logged in.";
}
BUT, this is not a very good solution. If you are creating user system, I would highly recommend to you to find tutorial on that subject and read them. If you google for php user authentication tutorial, I'm sure you'll find something usefull.
ALSO, you should use Header('Location:') instead of Header('Refresh:...').
Bookmarks