Jump to content

Apache ErrorDocument and $_SESSION vars


Eric_S

Recommended Posts

Hi,

 

In my ErrorDocument I'd like to be able to set some variables for future use then redirect using header() and access them.

 

.htaccess has this entry in it: ErrorDocument 404 /error.php

 

I can pass variables in cookies and all works:

 

setcookie('my_var', 'my_val');

header ("Location: $url");

 

I would rather set $_SESSION variables but I can't get it to work.

 

session_start();

$_SESSION['my_var'] = 'my_val';

header ("Location: $url");

 

then...

 

echo $_SESSION['my_var']; returns "". This works fine from other php scripts but not from ErrorDocument. What am I doing wrong here?

 

.htaccess has this in it:

 

ErrorDocument 404 /error.php

 

TIA.

Link to comment
https://forums.phpfreaks.com/topic/251038-apache-errordocument-and-_session-vars/
Share on other sites

Tried that too. I figured out the session_id changes but how can I grab the one from the last page or keep that session in the first place? I can pass the session_id in the query string but that's ugly. I can use cookies too and that works but sessions or post would be best.

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.