?
Solved

PHP Sessions lost in subdirectories Oo :(

Posted on 2010-01-08
10
Medium Priority
?
637 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:ahzulfi
  • 5
  • 4
9 Comments
 

Author Comment

by:ahzulfi
ID: 26209139
i wuz supposed to get an answer withing 43 minutes Oo ....alright ...never mind......stilll waiting....
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26210756
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?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26210786
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.
<?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>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26210890
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
// PAGE FOOTER
echo "<pre>\n";
echo "\n\n_COOKIE: "; var_dump($_COOKIE);
echo "\n\n_SESSION: "; var_dump($_SESSION);
die("END DIAGNOSTIC");

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26212007
Interesting.  Something is very sick there!  Who is your hosting company?
0
 

Author Comment

by:ahzulfi
ID: 26212860
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 ;)
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26239344
@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
0
 

Accepted Solution

by:
ahzulfi earned 0 total points
ID: 26269305
@RAY
m not also a NOVICE PHP developer ;)

the problem was that dear brother
i tested my script on 5 servers and only 1 was causing problem and didnt have any clue why it was causing problem except it was CGI
yesterday i find out it is beacause SERVER SETTINGS were such that if there is PHP.INI in root folder, CGI will consider it as SECURITY RISK and wont process any request that can b either session, post, get or any alike.

before there was PHP.INI in the folder and AFTER , there is no PHP.ini

hence fixed =D
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question