when user clicks on login button(index.php) I am calling chechlogin.php where I am checking loginId an password as-
if($count==1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
$_SESSION['UserId'] = $myusername;
$_session['SessionId'] = session_id();
header("location:LoggedUser.php");
}
in LiggedUser.php
<?php session_start(); //starting session
if (!isset($_SESSION[‘SessionId’]) || $_SESSION[‘SessionId’] == ”)
{
header(“location:index.php”);
}
?>
Problem: It is always going back to index.php page although I am entering right userid and password.I think session_id() is not working properly or ??
change $_session to $_SESSION.
btw session_register is deprecated and shouldn’t be used. See session-register manual for details.
btw #2. You don’t need to store sessionId in the $_SESSION, UserId is enough. So you code could look like:
login.php
loggeduser.php
EDIT:
Exit added as Emil suggested.