//login.php//
<?php $q=mysqli_query($conn,"select * from register where mid='$uname' AND pass='$pwd'");
if(mysqli_num_rows($q)===1)
{
$r=mysqli_fetch_row($q);
echo "logged in<br><br>You will be redirected in 3 sec";
$um=$r[0];
$cm=explode("@",$uname);
$rx=$cm[0];
$_SESSION['val']=$uname;
$valid=$_SESSION['val'];
$_SESSION['usnm']=$um;
// $un=$_SESSION['usnm'];
$_SESSION['rol']=$rx;
echo $_SESSION['rol'];
echo " ".$_SESSION['usnm'];
echo "<script>location.href='main.php';</script>";
echo "<script>alert($_SESSION[usnm])</script>;";
}
?>
//MAIN.PHP//
<?php
session_start();
// $_SESSION['usnm']=$um;
// echo $_SESSION['usnm'].": HI";
// $_SESSION['usnm']="Dhanush";
if(!empty($_SESSION['usnm']))
{
// // $var=$_SESSION['vali'];
// // echo "<script>window.location.replace('main.php');</script>";
}
else if(empty($_SESSION['usnm']))
{
echo "<script>alert($_SESSION[usnm]);</script>";
echo "<script>window.location.replace('index.html');</script>";
}
?>
The PHP code above is used for the validation of details entered by the user and when they match with that from those of database, then the session of name is being set and when ECHO is used in PHP page then it is seen but when ECHO SESSION is used in MAIN PAGE then the session value is empty. Can i know what is the problem down here? I tried and changed the script and even some session variables but still it failed to execute`