Page 1 of 1

Sessions combined with includes

Posted: Fri Dec 12, 2003 5:17 am
by yoma
hi

A problem i cannot seem to solve:

page a: i start a session in which i register a user
page b: has secret content => checks the session variables

no problem so far BUT

page c: has to be included in page b, but also needs the session variables checked.

=> i tried passing the sessionid via include but i couldn't get this working

HOW CAN ONE PASS A SESSION_ID TO AN INCLUDED FILE?

cu later folks.
:twisted:

Posted: Fri Dec 12, 2003 5:45 am
by twigletmac
You shouldn't need to pass the id to the included file, the included file should automatically have access to all the variables available to the parent file.

Mac

hmmm

Posted: Fri Dec 12, 2003 5:54 am
by yoma
tnx a lot for the quick answer

but i'm affraid it's not correct.

-if you don't start a session on the included page you don't have access to
$_SESSION['myvariable']

-if you do a session_start() on the included file a new session is started
-if u try to pass the session id via

include("http://myhost/mypage.php?PHPSESSID=$sessid") you get scripttimeout

Maybe there is someone who knows a small workaround for the problem?

Posted: Fri Dec 12, 2003 6:22 am
by JayBird
the thing is, include files ARE NOT run as separate scripts, when you inlcude a file into another, the two are combined, then run. So long as you include your file after your session_start() you should be okay. If not, there maybe another problem with the way you have constructed your script.

Could you show us you scripts!?

Mark

Re: hmmm

Posted: Fri Dec 12, 2003 6:51 am
by twigletmac
yoma wrote:tnx a lot for the quick answer

but i'm affraid it's not correct.

-if you don't start a session on the included page you don't have access to
$_SESSION['myvariable']
sorry that isn't true, the included file has access to the session variables as long as session_start() has been called in the parent file.
yoma wrote:-if you do a session_start() on the included file a new session is started
-if u try to pass the session id via

include("http://myhost/mypage.php?PHPSESSID=$sessid") you get scripttimeout
You can't pass variables to included files like that, it just won't work. The included file has access to the same variables that the parent file does.
yoma wrote:Maybe there is someone who knows a small workaround for the problem?
As Mark's said, we'll probably need to see your scripts to help you fix this.

However, you are trying to include a URL, have you tried using the relative path to the page? E.g.:

Code: Select all

include 'mypage.php';
assuming mypage.php is in the same folder as the parent page.

Mac

Mac

hey folks

Posted: Fri Dec 12, 2003 8:06 am
by yoma
thanx a lot for your patience:

don't ask me how but the bug went away...

anyway:

"PHP FOR PRESIDENT!" :P