Jump to content

Sessions get lost when changing directory?


Edward

Recommended Posts

Hi,

 

I'm having a problem with the following code.

 

index.php

header('Location: ftp/test/index2.php');

This works fine.

 

index.php

header('Location: ftp/index2.php');

This loses the session variables?!

 

Both directories ('ftp' and 'ftp/test') contain the same index2.php document. Does anyone know why this is happening?

 

index2.php

<?php

ob_start();
session_start();

echo '<p>user '.$_SESSION['username'].'</p>';
echo '<p>user 2'.$_SESSION['username_display'].'</p>';
echo '<p>pass '.$_SESSION['password'].'</p>';
echo '<p>token '.$_SESSION['token_login'].'</p>';
echo '<p>time '.$_SESSION['token_login_time'].'</p>';

ob_end_flush();

?>

 

Thank you!

 

 

 

Do you have session_start() on each page?

Also, sometimes you have to specify in some config file something about sessions & directories. Not a very helpful way to answer but I've never done it. I only vaguely remember someone mentioning the same thing when I was having session troubles once upon a time.

I do have ob_start(); and session_start(); at the start of each page. As I say, both index2.php documents are exactly the same (it was the same local file uploaded to both places). But it only works to one of the directories (bizarrely, the deeper one). If it's the config thing you mention I would need more info as I'm not sure what you mean. By the way, it works locally but not on my webspace.

 

Thanks CMC as I wasn't sure which order those two went in, but unfortunately this still hasn't fixed it. The target page won't retrieve the session variables unless I place it in a directory. I'm sure it used to work! It's still works in both directories when tested locally. Any ideas?? :-\

Right, I found out that if I delete my custom php.ini file (which is present to adjust file uploads as required), the sessions work. Can anyone see what could be causing the problem? Here is my php.ini file:

 

 

;;;;;;;;;;;;;;;;

; File Uploads ;

;;;;;;;;;;;;;;;;

 

; This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

Your web server can have other timeouts. E.g. Apache has Timeout directive, IIS has CGI timeout function, both default to 300 seconds. See the web server documentation for meaning of it

; max_execution_time = 300;

 

; This sets the maximum time in seconds a script is allowed to parse input data, like POST, GET and file uploads.

; max_input_time = 300;

 

file_uploads = On;

 

; Maximum allowed size for uploaded files.

upload_max_filesize = 100M;

 

; Maximum size of POST data that PHP will accept.

post_max_size = 110M;

 

memory_limit = 120M;

 

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.