problems with 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

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

problems with cookies

Post by psychotomus »

Code: Select all

<?php
	if (!isset($_COOKIE&#1111;'user_'])) &#123;
	setcookie("user_","",time()+60*60*24*30 ,"/naruto/","www.po2.net",1);
                setcookie("pass_","",time()+60*60*24*30 ,"/naruto/","www..po2.net",1);
		print $HTTP_COOKIE_VARS&#1111;'user_'];
	&#125; 

?>
im trying to store cookies, but it doesnt seem to write to my computer, and everytime i access $user_ it says undefined index... is there something wrong with my setcookies?
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

First off, you can't set a cookie and use it in the same page. Second of all, choose a standard and go with it, don't use $HTTP_COOKIE_VARS and then use $_COOKIE. I'd go with $_COOKIE
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

why cant you use a cookie after setting it on the same page?
i was testing them, none of them seemed to work.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

cookies wont set

Code: Select all

if (!isset($_COOKIE&#1111;'user_'])) &#123;
		setcookie("user_",".",time()+60*60*24*30 ,"/naruto/","www.po2.net",0);
		setcookie("pass_",".",time()+60*60*24*30 ,"/naruto/","www..po2.net",0);
		print 1;
	&#125;
no matter how many times i visit this page, the cookies wont end up on my computer. how do i set cookies?
Post Reply