From my logout.php file (below) i want to use the $_SESSION['username']=$myusername; on another php file
what code do i need to use to echo out the users name i have tried
the if statement is for letting signed in members keep logged in
i want to use the $usename from login.php and use in another php file
below is php were am trying to echo out the $username
reason i trying this i know the log bits work but the $usernot so echo the $username to see if work
am i using the wrong code to do echo out the user name this am new to php and proper stuck now
please can anyone give some code to show how i can go about calling the usersname from thew login page
<?php
session_start();
$_SESSION['username']=$myusername;
if (($_SESSION['auth'] == false)||(!isset($_SESSION['auth']))){
header("location:login.html");
}
echo $myusername;
?>
below is the login.php file where am trying to call the username from to echo in another php file
<?php
session_start();
$_SESSION['auth']=false;
$host="localhost"; // Host name
$username="20203800"; // Mysql username
$password="ralph"; // Mysql password
$db_name="two0203800"; // Database name
$tbl_name="ralphdb"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION['username']=$myusername;
$_SESSION['auth'] = true;
$_SESSION['password']=$mypassword;
$path = "location:members.php";
}else {
$path = "location:login.html";
}
header($path);
?>
what code do i need to use to echo out the users name i have tried
the if statement is for letting signed in members keep logged in
i want to use the $usename from login.php and use in another php file
below is php were am trying to echo out the $username
reason i trying this i know the log bits work but the $usernot so echo the $username to see if work
am i using the wrong code to do echo out the user name this am new to php and proper stuck now
please can anyone give some code to show how i can go about calling the usersname from thew login page
<?php
session_start();
$_SESSION['username']=$myusername;
if (($_SESSION['auth'] == false)||(!isset($_SESSION['auth']))){
header("location:login.html");
}
echo $myusername;
?>
below is the login.php file where am trying to call the username from to echo in another php file
<?php
session_start();
$_SESSION['auth']=false;
$host="localhost"; // Host name
$username="20203800"; // Mysql username
$password="ralph"; // Mysql password
$db_name="two0203800"; // Database name
$tbl_name="ralphdb"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$_SESSION['username']=$myusername;
$_SESSION['auth'] = true;
$_SESSION['password']=$mypassword;
$path = "location:members.php";
}else {
$path = "location:login.html";
}
header($path);
?>