session management works perfectly on xampp localhost.. not

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rushikant123
Forum Newbie
Posts: 3
Joined: Fri Jul 18, 2014 8:40 am

session management works perfectly on xampp localhost.. not

Post 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....
Last edited by Celauran on Fri Jul 18, 2014 9:09 am, edited 1 time in total.
Reason: Please wrap your code in syntax tags
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: session management works perfectly on xampp localhost..

Post by Christopher »

First, do you know that sessions work on the hosting server? Are they configured properly?
(#10850)
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Re: session management works perfectly on xampp localhost..

Post 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.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Post Reply