Page 1 of 1

session management works perfectly on xampp localhost.. not

Posted: Fri Jul 18, 2014 8:54 am
by rushikant123
login.php-->
--------------------------------------------------------------

Code: Select all

<?php
session_start();
if(isset($_SESSION['user']))
{
echo "a logged in user";
die("<script>window.location.href = 'page.php'</script>");

}
else
{
//authenticate
$_SESSION['user']="abc";
echo $_SESSION['user'];
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<br> 
authenticated & login done
<br>
<a href="page.php">page</a>

</body>
</head>
</html>
------------------------------------------------------------------------
page.php-->
-----------------------------------------------------------------------

Code: Select all

<?php
session_start(); 

if(isset($_SESSION['user']))
{
echo "a logged in user";

}
else
{
echo "no access";
exit();
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<br>
<a href="logout.php">logout</a>
</body>
</head>
</html>
-----------------------------------------------------------------
logout.php -->
---------------------------------------------------------------

Code: Select all

<?php
session_start();
if(isset($_SESSION['user']))
{
unset($_SESSION['user']); 
session_destroy();
}
else
{
echo "no access";
exit();
} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
logout done.. press back to check working..

</body>
</head>
</html>
----------------------------------------------------------------------------------------------------


On localhost ... on logout... when i click back button of browser... it shows me "no access" message...
and works perfectly...
But on hosting server... it shows previous page "page.php" even i have logged out... & value of session variable showing same even i refresh many times...???
plz help masters....

Re: session management works perfectly on xampp localhost..

Posted: Fri Jul 18, 2014 11:15 am
by Christopher
First, do you know that sessions work on the hosting server? Are they configured properly?

Re: session management works perfectly on xampp localhost..

Posted: Mon Aug 04, 2014 6:24 pm
by Pazuzu156
Sometimes when you logout and hit back, it takes you back to the previous page with everything still intact. From the gist of it, you're just going right back to the login page which redirects to page.php thus reviving the session. First off, the login should be handled by the server, and you shouldn't include java script do to your redirecting. Use header() instead.