This a Login Form from where we redirect to login_success.php page when username/password match with database values.
Checklogin.php
<?php
include 'config.php';
// username and password sent from form
$myusername=$_POST['email'];
$mypassword=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM drsignup WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['email']=$myusername;
$_SESSION['password']=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
Login_success.php
This form shows a Welcome message for the user who logs in and session starts.In below code, I am not able to get $_SESSION['email'] value with Welcome string and shows undefined index email.
I tried to collect session_id from session_id(); function which gives value like e9ubrn9v239o60tfalag6e6kt4. Please let me know why i am not able to get email id here.How can i store my session variables on my all php page.
<?php
session_start();
echo session_id();
SESSION_WRITE_CLOSE();
if(isset ($_SESSION['email']))
{
echo "Welcome $_SESSION['email']";
}
else
{
header("location:Drlogin.php");
}
?>
session_start()on the first page?session_start()to config file.