Jump to content

COOKIES in PHP


happyturtle

Recommended Posts

I am using cookies on my website and they will not travel when you click on a link.

 

I am using /folder/folder1/folder2/.

 

Can anyone help me?

 

	if($_COOKIE['per'] == "" AND $_GET['per'] == "") {
	$limit = 24;
} else {
	setcookie("per", $_GET['per'], time()+60*60*24*100, "/");
	$limit = $_COOKIE['per'];
}
if($_GET['per'] != "") {
	header("Location: /");	
}

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/195268-cookies-in-php/
Share on other sites

If you can provide more code, it might help tracking it down.  However, I see one potential problem with your posted code:

if($_COOKIE['per'] == "" AND $_GET['per'] == "") {
	$limit = 24;
} else {
	setcookie("per", $_GET['per'], time()+60*60*24*100, "/");
	$limit = $_COOKIE['per'];
}

You're saying if "per" is empty in the cookie and the URL, then you set the limit to 24.  Your else sets the "per" to the value of "per" in the URL.  What if this isn't set?  You could have the cookie filled and URL parameter empty, which would reset your cookie value to an empty value.

 

You can try this

if(empty($_COOKIE['per']))
{
if (empty($_GET['per']))
	setcookie('per', 24, time()+60*60*24*100, '/');
else
	setcookie('per', $_GET['per'], time()+60*60*24*100, '/');
}
$limit = $_COOKIE['per'];

 

You'll also want to verify the values of 'per.'  You can find out more here:

http://us2.php.net/manual/en/function.is-numeric.php

Link to comment
https://forums.phpfreaks.com/topic/195268-cookies-in-php/#findComment-1027099
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.