0

Hi Today I am facing one strange Problem After login validation I am storing the user name in session and redirecting it to some other page .

Validation page .

if (mysql_num_rows($sqlQuery) == 1) {
    session_start();
   $_SESSION['username']  = $login;
   print $_SESSION['username'];
   header("Location: dialout.php");

}

. on dialout.php I am trying to print session like

var_dump($_SESSION);

But it doesn't print anything .

some googling I found that problem might be in writing the session directory .

So to check that I wrote one script .

print session_save_path();
if (!is_writable(session_save_path())) {
    echo 'Session path "'.session_save_path().'" is not writable for PHP!'; 
    }
else{
 echo "writable -------------";
}

From above script I am getting writable.

Just wondering why my I am unable to access the session on dialout.php page

3 Answers3

1

In your Validation page,the following code should be at the top of the file, as first line in your code.

session_start();

It should be included in every page if you want to use session variable.

user4055288
  • 551
  • 5
  • 11
1

First, carry out these usual checks:

  1. Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening

  2. After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)

  3. Make sure cookies are enabled in the browser you are using to test it on.

  4. Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo(). Refer to this as to how to turn it off.

  5. Make sure you didn't delete or empty the session

  6. Make sure the key in your $_SESSION superglobal array is not overwritten anywhere

  7. Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.

  8. Make sure your file extension is .php (it happens!)

can all be found here: PHP session lost after redirect

Community
  • 1
  • 1
Elasek
  • 123
  • 7
0

Call session_start function in dialout.php befor accessing session variable like this :

session_start();
var_dump($_SESSION);
Mohsen Alizadeh
  • 1,595
  • 12
  • 25