Jump to content


Photo

Strange session problem


  • Please log in to reply
3 replies to this topic

#1 witt

witt
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 06 June 2006 - 11:28 AM

When someone logs in, this is set:

$_SESSION['user_id'] = $row[0];


If the user is logged in and a script like this script is run:


$location_id = $_GET['id'];

require_once ('includes/mysql_connect.php');

$query = "SELECT location, user_id FROM locations WHERE location_id='$locaton_id'";
$result = mysql_query ($query);
if (mysql_num_rows($result) == 1) {

$row = mysql_fetch_array ($result, MYSQL_NUM);

$location = $row[0];
$user_id = $row[1];

}

echo $user_id;

The user id of the person who's viewing the page is displayed while it should be the person selected from the database. If no one is logged in, the correct user id is shown. If, $user_id = $row[1]; and echo $user_id; are changed to anything else, like $hello = $row[1]; and echo $hello; everything works well.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 June 2006 - 12:25 PM

I also had this problem in a script that was very long and it took me days to realise it kinda sets sessions as a global but i'm also not sure why...

Maby someone can enlighten us?

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 witt

witt
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 06 June 2006 - 03:35 PM

any other ideas?

#4 dckarina

dckarina
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 06 June 2006 - 04:02 PM

hello,
i'm just learning php but from what i've read if you have register_globals in php.ini set as ON then you can acces a session variable - in your case user_id - only by using it's name (without using $_SESSION['name']). so, from what i can see, and if php is like other programming languages, your user_id variable (inside IF) is just local and if you have register_globals on then you will acces the session variable called user_id. i'm not 100%. corect me if i'm wrong. hope this helps.
Karina




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users