[RESOLVED] Setting cookies

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

User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Replace time() - 3600 with 0. Also remember that the $_COOKIES array doesn't get cleared until next request.
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post by LuiePL »

I threw this code into the top of my "Logout.php" page, and it works in IE6 but not Firefox:

Code: Select all

$expiry = 1;
setcookie('user', '', $expiry);
header('Location: index.php');
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Clear your cache in FF. Also, use a full URL instead of a relative when using the header() function, as per the manual.
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post by LuiePL »

I tried clearing the cache, deleting the original cookie, and using the full http://www.mydomain.org/Directory/index.php and still no luck. It's still working in IE though.
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post by LuiePL »

Set it to the following, and moved it over to a subdomain and now it's working like a charm.

Code: Select all

if (isset($_COOKIE['user']))
	{
		$cookie_info = explode("-", $_COOKIE['user']);
		$name = $cookie_info[0];
		$pass = $cookie_info[1];
		$cookie_data = $name.'-'.$pass;
		$expiry = 1;
		$directory = "";
		$domain = "subdomain.mydomain.org";
	
		setcookie ("user", $cookie_data, $expiry, $directory, $domain, "0");
		header('Location: http://subdomain.mydomain.org/index.php');
	}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

When you set the domain in the first script, was it 'domain.com' or '.domain.com'?
LuiePL
Forum Commoner
Posts: 40
Joined: Fri Aug 04, 2006 11:38 pm

Post by LuiePL »

".domain.org"
Post Reply