Thank you so much for replying. i've written a code to prevent session hijacking but it doesnt seem to be working.
everytime a user succesfully logs in this script is executed.
PHP Code:
$session = uniqid();
$_SESSION['session'] = $session;
$query = " UPDATE table
SET session = '$session'
WHERE email = '$email' "; /*Storing session id*/
$result = (mysql_query($query));
and on the members page i have this
PHP Code:
$session = mysql_real_escape_string($_SESSION['session']);
$email = mysql_real_escape_string($_SESSION['email']);
$query = "SELECT session FROM table
WHERE email = '$email'";
$result = mysql_query($query);
$storedsession = mysql_fetch_array($result);
$storedsession = $storedsession["session"];
if (!isset($_SESSION['email']) || $session != $storedsession)
{echo 'You need to log in first';
session_destroy();
session_unset();}
am i using session_unset and session_destroy correctly? i was thinking if anyone manages to fake a session id, it would be best to unset the session variables. but somehow when i included session_unset and session_destroy, the user never gets logged in on the members page even if the user was already previously logged in.
i've tried a simple code like this
PHP Code:
session_start();
$_SESSION['test'] = 1;
if(isset($_SESSION['test']))
{session_destroy();
session_unset();}
echo $_SESSION['test'];
however the result ends up as 1. did i miss out on anything?
thank you very much for your time.