$_SESSION question
Moderator: General Moderators
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
$_SESSION question
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.
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
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
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);
?>now if you want to use the session id in the next page have a
line
Code: Select all
<?php
$sessionId = $_GET["sessionId"];
?>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
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.
I hope that will give you some info on what youre looking for.
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
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>";
?>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");