Php session help requested
February 13, 2005 4:27 PM   Subscribe

Php session help requested. [MI]

Using php 4, my session variables do not want to be passed from page to page. They register fine from a form and are usable on the form's action page but, otherwise, they are no place to be found.
Suggestions?
posted by Scottk to Computers & Internet (9 answers total)
 
I store teh variables from a form using the following block:

$std_id = $_POST['std_id'];
$last = $_POST['last'];
$_SESSION['std_id'] = $std_id;
$_SESSION['last'] = $last;

I can call the set $_SESSION variables on that page only, and not any other pages.
posted by Scottk at 4:30 PM on February 13, 2005


Do you have sessions set to auto start in your (I believe) php.ini? You can also call session_start() if you have a page (or include) that will always be present (or just put it at the top of every page to make sure the session starts).

I actually ran into the same problem last night. Adding session_start() to an include I require() on every page fixed it.
posted by socratic at 4:41 PM on February 13, 2005


Yeah, I have session_start atop every page.
posted by Scottk at 4:43 PM on February 13, 2005


Are you accepting cookies in your browser? Are you blocking cookies with any sort of firewall or proxy solution (like privoxy)? (ran into that one once too.. almost punched myself in the face for it.. :) )
posted by socratic at 4:49 PM on February 13, 2005


Hah. That's a negative.
posted by Scottk at 4:50 PM on February 13, 2005


Hm. If you echo $_COOKIE['PHPSESSID'] do you get a value?

What about echoing session_save_path()? Does the path to save session data exist?
posted by socratic at 4:56 PM on February 13, 2005


(that first question, about PHPSESSID, may be a wild goose chase, as the PHP session cookie may be called something else, but I believe PHPSESSID is the default.)
posted by socratic at 5:00 PM on February 13, 2005


If you are doing any redirections or calling exit() that can cause the session not to get saved. You can get around this by calling session_write_close.
posted by revgeorge at 8:01 PM on February 13, 2005


(You didn't mention what minor version of PHP you're running; before 4.1, $_SESSION wasn't an superglobal variable, prior to 4.0.6 $_SESSION didn't exist but was instead $HTTP_SESSION_VARS, and before 4.0.3, there was a variable, track_vars, that needed to be set to true for the session-related variables to even make it into the $HTTP_SESSION_VARS array. Which version is it you're running?)

In any event:
  1. Find a page that you've discovered doesn't have access to the session variables. (You say that it's pretty much every page, so this shouldn't be hard.)
  2. Insert the following block of code at the very top of the page: <?php session_start(); print_r($_COOKIE); print_r($_SESSION); echo session_id(); ?>
  3. Change one of your other pages -- one that both sets a session variable and includes a form -- so that the form's action points to the page that you modified in step 2 above.
  4. Visit the page from step 3 in your browser, submit the form, and then tell us what the resultant page shows.
(Of course, if you're on a version prior to 4.0.6, substitute in the appropriate variables for $_COOKIE and $_SESSION...)
posted by delfuego at 8:05 PM on February 13, 2005


« Older remote control for my XP-based mp3/video player?   |   Windows XP utility that lists details of what's... Newer »
This thread is closed to new comments.