Jump to content

Strange session problem


witt

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/11315-strange-session-problem/
Share on other sites

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

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.