Jump to content

Strange PHP Session Behavior


nbaztec

Recommended Posts

To start off, I was designing a site in PHP 5.3.5, I wrote the following code:

 

//test_login.php 
session_start(); 
.
.
if([test credentials])
  $_SESSION['user'] = '1';
else
  //Do Stuff

 

//File_2.php
if(!isset($_SESSION))
session_start(); 

echo $_SESSION['user'];
echo $_SESSION['user'];
echo $_SESSION['user'];

 

Now on my localhost(PHP 5.3.5), it correctly outputs: 111

 

But when I put the same script on my webserver (PHP 5.2.3), the same script shows output: 011

 

It's as if the reference to $_SESSION['user'] isn't made until it's referenced for the 2nd time.

 

Can anyone kindly enlighten me on this issue.

 

Regards,

Nisheeth Barthwal

Link to comment
https://forums.phpfreaks.com/topic/244923-strange-php-session-behavior/
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.