Page 1 of 1
$_SESSION question
Posted: Fri Jan 23, 2004 10:01 am
by php_wiz_kid
How do you use the session id in a URL? I'm using header() to redirect my page and the php docs said that if you do that you have put the session id in the url.
Posted: Fri Jan 23, 2004 10:33 am
by php_wiz_kid
Can anyone help?
Posted: Fri Jan 23, 2004 1:23 pm
by Sym
Well I'm not too sure what kind of set up you have,
so I'll make an assumptions that you have created a variable called $sessionId that has your session id.
so for instance if the user has just logged in you would redirect them with
Code: Select all
<?php
header("Location: http://www.yoursite.com/index.php?sessionId=".$sessionId);
?>
That will put the session id in the url.
now if you want to use the session id in the next page have a
line
Code: Select all
<?php
$sessionId = $_GET["sessionId"];
?>
Posted: Fri Jan 23, 2004 2:31 pm
by DuFF
I've been using headers() in a user authentication system using sessions and I've never had any problem not passing the sessionID. Could you point out the part that mentions that? I skimmed the docs but didn't really find anything.
Posted: Fri Jan 23, 2004 3:12 pm
by ol4pr0
REading up on some Redirect with Session id.
Book said this to me. ( Book not so very new since in this country its hard to buy any php books ) Also i have used a translater ( online ) to have it in english

, and corrected it as best as i could.
if sessions are enabled, but a user doenst exept cookies ( which they never or almost never do ;-( ) whats sent to a browser is for example
Code: Select all
<?
echo "
< a href="train.php?PHPSESSIONID=23kjlkajfa833r3jkljafd8">Take a train</a>";
?>
php adds those session ids to the url so they are passed along to the next page. Froms are modified to include a hidden element that passes the session ID. Redirects with the location header arent automaticly modified, so you have to add a session id to them yourself using a SID constant.
Code: Select all
// EXAMPLE
$redirect_url = 'http://youredomain.com/somepage.php';
if (redirect('SID') && (! isset($_COOKIE[session_name()]))) {
$redirect_url .= '?' . SID;
}
header ("location: $redirect_url");
I hope that will give you some info on what youre looking for.