SID problem

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
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

SID problem

Post by AGISB »

I got following code

Code: Select all

session_start();
$sess = session_id();
if (!ereg("(^([a-f0-9]{32})$)", $sess)) {
	session_regenerate_id();
}
$sid_id = strip_tags(SID);
if (!empty($sid_id) ) {
	$s_add = "?".$sid_id;
} else {
	$s_add = "";
}
This leads to the following. If the browser opens a session first time it apparently gets a SID even though cockies are enabled. So it places $s_add behind all links. When the next page is called the url part is gone and all works fine.
This does not limit the site functionality but it does bother me.

Anyone got an idea how to avoid this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd imagine trans_sid is on..

I think the following should tell you.

Code: Select all

echo 'session.trans_sid is ' . (ini_get('session.trans_sid') == 1 ? 'on' : 'off');
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Trans ID is off. The above coding places the sid into the URL manually when cockies are off. Well as I said it does it on the first site call whether cockies are off or on.

I probably use a session var and session_regenerate_id to get around this.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

Code: Select all

if ($_SESSION['status'] <> 'on') {
	$_SESSION['status'] = 'on';
	session_regenerate_id();
}
not even this gets me to solve this problem. Very weird
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

basically it has to though.. because the server won't know if cookies are on until the second page request..
Post Reply