ahzulfi
asked on
PHP Sessions lost in subdirectories Oo :(
I am the developer of ClipBucket
currently working on v2
now the problem is, it works absolutely perfect on apache2handler server api but fails on CGI
now there is an issue that i want to resolve first is that
- index.php
- /includes/config.inc.php
- /includes/common.php
- includes/admin.inc.php
- /admin_area/index.php
- config.inc.php and admin.inc.php has code that includes common.php
- index.php includes config.inc.php
- /admin_area/index.php includes admin.inc.php
- session_start() is called in common.php - so session will be started in every page
the actuall problem is
i start a session lets say $_SESSION['username'] = "i am the user"; in index.php
that supposed to work in /admin_area/index.php if i call echo $_SESSION['username']
but what happens is that , it not only gives blank echo $_SESSION['username'] but also destroys the $_SESSION['username'] that even doesnt work on index.php
simply
- session is lost whenever it is called in a subdirectory
ie /index.php (WORKS)
but wont work in admin_area/index.php
ie IF admin_area/index.php works
then it wont work in /index.php
i hope you understand what the problem is
Regards
currently working on v2
now the problem is, it works absolutely perfect on apache2handler server api but fails on CGI
now there is an issue that i want to resolve first is that
- index.php
- /includes/config.inc.php
- /includes/common.php
- includes/admin.inc.php
- /admin_area/index.php
- config.inc.php and admin.inc.php has code that includes common.php
- index.php includes config.inc.php
- /admin_area/index.php includes admin.inc.php
- session_start() is called in common.php - so session will be started in every page
the actuall problem is
i start a session lets say $_SESSION['username'] = "i am the user"; in index.php
that supposed to work in /admin_area/index.php if i call echo $_SESSION['username']
but what happens is that , it not only gives blank echo $_SESSION['username'] but also destroys the $_SESSION['username'] that even doesnt work on index.php
simply
- session is lost whenever it is called in a subdirectory
ie /index.php (WORKS)
but wont work in admin_area/index.php
ie IF admin_area/index.php works
then it wont work in /index.php
i hope you understand what the problem is
Regards
Not sure I exactly understand the problem, but I will try to help.
Do you have error_reporting(E_ALL) set in all scripts? That will help you catch any undefined vars.
You have session_start() at the top of all scripts, right?
Do you have error_reporting(E_ALL) set in all scripts? That will help you catch any undefined vars.
You have session_start() at the top of all scripts, right?
This will test a session handler. If you run it and the var increments correctly, your session handler is almost certainly set up right.
Possible issues could include the path to your session-save area. Usually that is a /tmp file above the WWW root.
Possible issues could include the path to your session-save area. Usually that is a /tmp file above the WWW root.
<?php // RAY_session_test.php
error_reporting(E_ALL);
// START THE SESSION (DO THIS FIRST IN EVERY PHP SCRIPT ON EVERY PAGE)
session_start();
// SEE IF THE SUBMIT BUTTON WAS CLICKED
if (isset($_POST['fred']))
{
// SEE IF THE CHEESE VARIABLE IS SET IN THE SESSION ARRAY
if(!isset($_SESSION['cheese']))
{
// IF CHEESE IS NOT SET, SET IT TO ONE
$_SESSION['cheese'] = 1;
} else {
// IF CHEESE IS SET, ADD ONE TO IT
$_SESSION['cheese']++;
}
}
// END OF SCRIPT
?>
<html><head><title>Session Test</title></head>
<body>
Currently, $_SESSION["cheese"] contains: <?php echo $_SESSION['cheese']; ?> <br/>
<form method="post">
<input type="submit" value="click" name="fred">
</form>
</body>
</html>
Here is another debugging technique that may be helpful. In each page footer, add something like the code snippet - this allows you to see what you had in the external vars. If you missed a session_start() because of conditional logic, that might show up here
One other question - do you manipulate the session cookie at all, or do you just set it and forget it?
I think it may be useful to see the code that starts your session and the code that fails; not 100% sure I follow the path in the O/P.
best regards, ~Ray
One other question - do you manipulate the session cookie at all, or do you just set it and forget it?
I think it may be useful to see the code that starts your session and the code that fails; not 100% sure I follow the path in the O/P.
best regards, ~Ray
// PAGE FOOTER
echo "<pre>\n";
echo "\n\n_COOKIE: "; var_dump($_COOKIE);
echo "\n\n_SESSION: "; var_dump($_SESSION);
die("END DIAGNOSTIC");
ASKER
Interesting. Something is very sick there! Who is your hosting company?
ASKER
AAARGGGGGGGGG!!!!!!!!!!!!
o man......what the.......loooollz........ ..
i just cant believe on ma eyes, its the worst experience of my whole life
problem was caused by PHP.INI that was placed in my root folder
post_max_size = 2147483648;
upload_max_filesize = 2147483648;
max_execution_time = 1000;
max_input_time = 12000;
memory_limit = 32M;
NOW EVERYTHING IS WORKING GREAATTT!!!!!!!! THANKS ALL FOR YOUR SUGGESTION ;)
o man......what the.......loooollz........
i just cant believe on ma eyes, its the worst experience of my whole life
problem was caused by PHP.INI that was placed in my root folder
post_max_size = 2147483648;
upload_max_filesize = 2147483648;
max_execution_time = 1000;
max_input_time = 12000;
memory_limit = 32M;
NOW EVERYTHING IS WORKING GREAATTT!!!!!!!! THANKS ALL FOR YOUR SUGGESTION ;)
@ahzulfi, Premium Service Member, I am going to post an objection to closing this question because I am not exactly a novice in PHP and I have absolutely no idea what your answer at ID: 26212860 has to do with session-related issues.
Please post the before-and-after information so we have a good answer for the PAQ.
Thanks and regards, ~Ray
Please post the before-and-after information so we have a good answer for the PAQ.
Thanks and regards, ~Ray
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER