Forum Moderators: coopster

Message Too Old, No Replies

Session id

How to read it on another page.

         

itKiwi

5:13 pm on Oct 21, 2006 (gmt 0)

10+ Year Member



Using this code

echo "session_id = ". session_id().'<br>';

I can read the session_id on the page on which it was created (my form).

What do I have to do to read it on another page (my form handler)? I've also tried

echo "session_id = ". $_SESSION['session_id'].'<br>';

but still no luck.

Thanks for any help.

jatar_k

5:26 pm on Oct 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



do you have session_start() at the top of every page?

itKiwi

7:28 pm on Oct 21, 2006 (gmt 0)

10+ Year Member



No, only at the top of the first page, which is the form.

eelixduppy

7:39 pm on Oct 21, 2006 (gmt 0)



You must initialize the session using session_start on the pages. Example:

[url=http://us3.php.net/manual/en/function.session-start.php]session_start[/url]();
echo 'session_id = '.session_id().'<br>';

itKiwi

7:44 pm on Oct 21, 2006 (gmt 0)

10+ Year Member



I had 'assumed' that a "session_start" on the formhandler page would give a new session_id, which is what I am trying to track from the form page.

dreamcatcher

7:37 am on Oct 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can pass the session id from the form page using a hidden field:

<input type="hidden" name="sid" value="<?php echo session_id();?>">

Accessed via $_POST['sid'];

or append it to the form action for a get request:

<form method="post" action="index.php?sid=<?php echo session_id();?>">

Accessed via $_GET['sid'];

dc

eelixduppy

1:28 pm on Oct 22, 2006 (gmt 0)



^^ Indeed. Here's the documentation [us3.php.net] on the above.

One additional note is that you can enable use_trans_id [us3.php.net] and relative URIs will be changed to contain the session id automatically.

Good luck ;)

itKiwi

8:01 pm on Oct 22, 2006 (gmt 0)

10+ Year Member



Thanks dc,

Just the answer I needed (simple, direct).

Alan