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!
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.
setcookie("cookietest", "1", time()+86400*30);
///Sets it to expire in 30 days
if ($_COOKIE["cookietest"] == 1)
{
ini_set("session.use_only_cookies", "1");
}
"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."
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.
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.
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.