PHPSESSID appearing in address

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

Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Hrm... using this code and it's not changing the behavior. I have checked and am certain that the condition is evaluating true. But I still see the session id in the URL.

Code: Select all

setcookie("cookietest", "1", time()+86400*30);
	
	///Sets it to expire in 30 days
	
	if ($_COOKIE["cookietest"] == 1)
	{
		ini_set("session.use_only_cookies", "1");
	}
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Well I found the problem.

"For newcomers, cookies are ONLY available after you change the page that has set a cookie. In the new page you can see the cookie that was set accessing the $_COOKIE array."

I have not yet found the solution, exactly.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

You cannot access a cookie on the same script as you set it, that isn't how they work. They're not active in the browser until the subsequent page call.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

Hmm. Regardless of that, this script is called with every page load. And yet the PHPSESSID continues to appear even on subsequent pages, even when I know the cookie has taken. And I've restarted Apache and all that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

From what I've seen, the php preprocessor keeps it there if it appeared on the first load...
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

feyd - yeah, looks that way here on a quick test.

Just write a script that sets a cookie - redirect to another script (using a header location, so the user will never see it happen) which checks if the cookie exists - if not, use the trans ID, if so - set the use cookies on.

You'll need these as sort of "jump" pages through the start of your site. But like I said, if you use a header location: transfer then the user will NEVER see it happen.
Post Reply