3
<?php
session_start();
print_r($_SESSION);
if(empty($_SESSION['a'])) {
    $_SESSION['a'] = mt_rand();
}

print_r($_SESSION);
?>

The code is placed on page1.php and after every page refresh the variable 'a' value is being set again and again. Whats the problem with the above code?

Mohammad Sharaf Ali
  • 569
  • 1
  • 4
  • 19

3 Answers3

0

The problem was with the php file encoding system. I opened the php file in latest notepad++ version and checked the "Encoding" and it was UTF-8 with BOM and I changed it to just UTF-8. And wolla it worked like a charm :-)

Mohammad Sharaf Ali
  • 569
  • 1
  • 4
  • 19
0

This is the issue of Encoding. Please open your file on notepad++ new version and set file into Encoding in UTF-8. I hope your issue will be fix :)

okconfused
  • 3,567
  • 4
  • 25
  • 38
-1

see this answer.

It says that you need to set proper read/write privileges to the php/webserver process' user.

Make sure that the /var/lib/session/ directory is readable/writable for www-data.

Community
  • 1
  • 1
Caleb Lewis
  • 523
  • 6
  • 20