display user data after login
Posted: Tue Aug 11, 2009 5:17 pm
hello guys,
i have a site, and i want when the user login into the secure site shows <?php echo "Bienvenido, {$_SESSION['$Real Name]}"; ?> instead the username i want something like this Welcome, Joe Satriani instead Welcome, jsatch.
the code that i have for the login is this one:
<?php session_start();
//Connect to database from here
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//select the database | Change the name of database from here
mysql_select_db('aasala');
//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT user_name, password FROM tbl_user WHERE user_name='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)>0)
{
//compare the password
if(strcmp($row['password'],$pass)==0)
{
echo "yes";
//now set the session from here if needed and query the real name
$_SESSION['u_name']=$user_name;
}
else
echo "no";
}
else
echo "no"; //Invalid Login
?>
An the secure.php is this one
<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name']))
header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:index.html");
}
?>
Here goes the html
i have a site, and i want when the user login into the secure site shows <?php echo "Bienvenido, {$_SESSION['$Real Name]}"; ?> instead the username i want something like this Welcome, Joe Satriani instead Welcome, jsatch.
the code that i have for the login is this one:
<?php session_start();
//Connect to database from here
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//select the database | Change the name of database from here
mysql_select_db('aasala');
//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT user_name, password FROM tbl_user WHERE user_name='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)>0)
{
//compare the password
if(strcmp($row['password'],$pass)==0)
{
echo "yes";
//now set the session from here if needed and query the real name
$_SESSION['u_name']=$user_name;
}
else
echo "no";
}
else
echo "no"; //Invalid Login
?>
An the secure.php is this one
<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name']))
header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:index.html");
}
?>
Here goes the html