Sessions don't work at all?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mattachoo
Forum Newbie
Posts: 5
Joined: Fri Feb 20, 2009 12:48 pm

Sessions don't work at all?

Post by Mattachoo »

I've worked with sessions before in PHP. All of a sudden, they stopped working. My webhost recently did this "migration" thing where they changed a bunch of stuff (like upgrading from PHP 4 to PHP 5, etc.). Now, sessions don't work at all. I tried a simple test to see if they worked, and guess what, they don't. Here is my example:

Code: Select all

<?php
  //first_page.php
  session_start();
  print("<html><pre>");
 
  $_SESSION["MyLogin"] = "FYICenter";
  print("A value saved in the session named as MyLogin.\n");
 
  $_SESSION["MyColor"] = "Blue";
  print("A value saved in the session named as MyColor.\n");
 
  print("Click <a href=next_page.php>Next Page</a>"
    ." to retrieve the values.\n");
  print("</pre></html>\n");
?>

Code: Select all

<?php
  //next_page.php
  session_start();
  print("<html><pre>");
 
  $myLogin = $_SESSION["MyLogin"];
  print("Value of MyLogin has been retrieved: ".$myLogin."\n");
 
  $myColor = $_SESSION["MyColor"];
  print("Value of MyColor has been retrieved: ".$myColor."\n");
 
  print('</pre><a href="first_page.php">Click here to go back</a></html>\n');
?>
When I run the script, here is what I get in return:

Code: Select all

Value of MyLogin has been retrieved: 
Value of MyColor has been retrieved: 
Click here to go back\n
Absolutely nothing.

So my question is, what could be preventing my sessions from working? Also, when I click on the next_page.php link, it transfers a ?PHPSESSID variable in the URL. Maybe this has something to do with the problem? I don't know. Any help will be appreciated. Thanks!
Last edited by Benjamin on Tue May 19, 2009 9:52 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: Sessions don't work at all?

Post by jazz090 »

maybe they also disabled the way the stored session data. you are meant to save it in cookies or pass it as a parameter in the url, chnaces are they turned of save session data as cookie
Mattachoo
Forum Newbie
Posts: 5
Joined: Fri Feb 20, 2009 12:48 pm

Re: Sessions don't work at all?

Post by Mattachoo »

Ah ha! Ok, I'm getting somewhere. It was suggested to me that I put

Code: Select all

 ini_set("display_errors", "1");
  error_reporting(E_ALL);  
at the start of my code. Now I get two error messages when I run my script.

Code: Select all

 
Warning: Unknown: open(/var/php_sessions/sess_2a6b97f59f33efcf2366295b4e204ba5, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
 
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0
So what should I set the session.save_path to in the ini file? I am going to talk to customer support today. Hopefully they will be able to fix it.
Last edited by Benjamin on Tue May 19, 2009 2:08 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Sessions don't work at all?

Post by Benjamin »

The system administrator will need to set the session save path and ensure that it's writeable. You may be able to set it to the /tmp directory using ini_set().
Post Reply