Jump to content

php sessions not acting as intended


bouwob

Recommended Posts

ok I have this at the top of every page

 

if (!isset($_SESSION['user']))
{
session_start();
$_SESSION['user'] = "4";
$_SESSION['browse'] = "4";
echo "ho";
}

if (isset($_SESSION['user']))
{
echo "hi";
$userid = $_SESSION['user'];	
}
else
$userid = "";
if (isset($_SESSION['browse']))
$browseid = $_SESSION['browse'];	
else
$browseid = "";

echo $_SESSION['browse']."----".$_SESSION['user'];

 

when I get to any page I get a printout of "hohi4----4 "

 

and then I have a login page with this code

if ($_POST["user"] != "UserName" && $_POST["password"] != "Password")
	{
	$query = "select username, userid from users where username = '".$_POST["user"]."' and password = '".$_POST["password"]."'";
	$result = querydatabase ($query);
	while($row = mysql_fetch_assoc($result))
		{
		$username = $row['username'];
		$userid = $row['userid'];
		}
	echo ($username == $_POST["user"]).$userid;
	if ($username == $_POST["user"])
		{
			$_SESSION = array(); 
			session_destroy();
			session_start();
			$_SESSION['browse'] = "5";
			$_SESSION['user'] = $userid;
			$whatToDo = "display uname"; 
		}
}

 

when I go to that page and login I get a print out of this "11hi5----1"

 

ok everything up untill this point is working as intended. the problem is that when I then click a home link I get "hohi4----4 " when it should say "hi5----1". Are sessions directory sensitive? The home page does not have any other session code other than the 1st section of code I posted. The sessions are dieing when going from the login page to the home page.

 

any ideas?

 

if you go to

 

http://www.nolanryancardmuseum.com/login/index.php

 

you can play around with it. just hit submit to login

 

tia

Link to comment
https://forums.phpfreaks.com/topic/51929-php-sessions-not-acting-as-intended/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.