PDA

View Full Version : Trouble with sessions and include();


RayBanJockey
09-20-2006, 09:55 AM
Hello,

Maybe you can help me with this. Been searching the web a lot to no avail.

My problem is basically this: When I include a .php file somewhere in the original php file, the included file doesn't inherit the session. I don't do a session_start() in the included file, and I'm certain the one in the original file is before any output. I don't get any error messages at all, the session variables are just blank.

ORIGINAL.PHP
<?
session_start();
$_SESSION['myVariable'] = 1;
include('INCLUDE.PHP');
?>

INCLUDE.PHP
<?
echo $_SESSION['myVariable'];
?>

Output is blank, nothing, as $_SESSION['myVariable'] isn't found in the included script.

Any ideas?

Thanks,
Alex

percepts
09-20-2006, 10:31 AM
works for me.

delete all your old sessions and clear cache. Then try again.

percepts
09-20-2006, 11:04 AM
another possibility but I'm not sure is that INCLUDE.PHP is in uppercase.

on my windows system .PHP in uppercase is parsed by PHP but that may be dependant on how your web server is configured.

The apache conf file has an entry

AddType application/x-httpd-php .php

you may need to add one with upper case but I'm guessing here.

AddType application/x-httpd-php .PHP

RayBanJockey
09-20-2006, 11:20 AM
Works for me too :(

I'm seriously confused now. The example works fine, my proper code which is built exactly in this manner doesn't. I think I'm going to have to really really look through everything again.

Thanks for the tip on cache clearing btw, I have a feeling I should be doing that sometimes regardless.

raf
09-20-2006, 11:22 AM
try replacing the shorttags --> <? tot <?php

with shorttags, it doesn't work on my machine. with the <?php tags, id does work (i've used the exact same code, including the uppercase filename).

besides, you should never rely on shorttags being enabled.

percepts
09-20-2006, 12:20 PM
Works for me too :(

I'm seriously confused now. The example works fine, my proper code which is built exactly in this manner doesn't. I think I'm going to have to really really look through everything again.

Thanks for the tip on cache clearing btw, I have a feeling I should be doing that sometimes regardless.

I would also suggest clearing your old sessions out if you can. They are usually stored in /tmp or /sess.

Cos some will stil be current it can sometimes confuse things. Just delete them if they are on your local system