$_SESSION question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

$_SESSION question

Post 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.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

Can anyone help?
Sym
Forum Newbie
Posts: 3
Joined: Fri Jan 23, 2004 1:05 pm
Location: Vancouver, B.C.

Post 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"];
?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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.
Post Reply