0

Having serious problems with headers and session variables. Read related posts but none helped me.

I'm using sessions to store some info about the user logged in e.g. name, user_id, etc.

To start with, let's say $_SESSION['user_id']=6;.

Then let's sat I want to view someone's profile. There is a dropdown list where you select the person whose profile you want to view, then click View. The processing page for this looks up for the user_id of the person you selected and redirects you to the person's profile.

The code is something like this:

<?php session_start();
$_SESSION['user_id']=1; //this is the user_id of the person logged in..
/*......many lines of code*/
?>
<select name="user_id">
<option value="4">George Thuo</option>
<!--other many options-->
</select>
<input type="submit" name="view" value="View">

Then this will direct you to the processing page which looks something like this:

$user_id=$_POST['user_id'];
header("Location: view.php?user_id=".$user_id);

See that before we used the header, $_SESSION['user_id']=1; But after the header is user, I don't know why but $_SESSION['user_id']=4;(the user_id passed via the $_POST method

Why is it changing?

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
gthuo
  • 2,376
  • 5
  • 23
  • 30
  • Do you have `register_globals` on? See [this](http://stackoverflow.com/questions/3593210/what-are-register-globals-in-php) for an explanation on what it is. – kittycat Mar 02 '13 at 13:45
  • I've read it. I don't remember turning it on or off. Whats the default setting, or how do I know what it is set to? – gthuo Mar 02 '13 at 14:24
  • 1
    Run `phpinfo();` and search for `register_globals` – kittycat Mar 02 '13 at 15:04
  • thank you alot..the answer lies with `register_globals`. All is well now – gthuo Mar 13 '13 at 14:27

0 Answers0