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!

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?? :-\

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.