Page 1 of 1

Problem with cookies and header() (newbie)

Posted: Sat Oct 09, 2004 10:04 am
by mrclash
Hi,
I'm having a problem with cookies. I use setcookie() in signmein.php to set 2 cookies and just after that I call header():

Code: Select all

setcookie ("iguser", md5($_POSTї'username']), $time+3200);
setcookie ("igpass", md5($_POSTї'password']), $time+3200);
			
header ("Location: http://foo.com/admin.php");
The problem is that in admin.php I'm trying to get those cookie values and they seem to be empty (not set).

Code: Select all

session_start();

if (isset($_COOKIEї'iguser']) &&  isset($_COOKIEї'igpass']))
{
	if (!($_COOKIEї'iguser'] == md5($user_name) && $_COOKIEї'igpass'] == md5($user_pwinput)))
	{
		echo $_COOKIEї"iguser"];
		echo $_COOKIEї'igpass'];
		//header("Location: signin.php");
		//exit();
	}
}


It has to be a very obvious thing, I know (maybe an include?) but any help will be greatly received. As I said in the topic, I'm a newbie in PHP :P

Thanx.

Posted: Sat Oct 09, 2004 10:13 am
by feyd
the cookie setting may not happen before your browser redirects. Are you sure they are setting in the first place?

Posted: Sat Oct 09, 2004 11:27 am
by twigletmac
Which webserver and version are you using? Some have issues with this.

Mac

Problem with cookies and header() (newbie)

Posted: Sun Oct 10, 2004 8:58 am
by mrclash
Ok, I didn't try it before, the second page has nothing to do with the problem...In fact, I'm not setting the cookies, but I don't know why!

Code: Select all

setcookie ("iguser", md5($_POST['username']), $time+3200);
setcookie ("igpass", md5($_POST['password']), $time+3200);

if (isset($_COOKIE["iguser"]) &&  isset($_COOKIE["igpass"])) 
	{echo "Cookies registered";}
else	{echo "Argh";}
The setcookie() function doesn't do anything. Any hint?

Posted: Sun Oct 10, 2004 10:11 am
by feyd
Post a link to this cookie setting script and I will tell you the headers it's actually sending out. I'd bet your server removes the cookie headers or your browser ignores them in some fashion because of the redirect you are doing.

Problem with setcookie()

Posted: Mon Oct 11, 2004 6:27 am
by mrclash
You can try it at http://www.mans-hq.net/igrafic/admin/signin.php.

Code: Select all

login: dev
password: dev00
I don't think that it is a problem with the browser, is Firefox 1.0PR with all cookie settings activated. I have revised it thousand times...

Thanx ;)

Posted: Sun Oct 17, 2004 5:42 pm
by feyd
I don't have the time right now to fiddle with my header script to get posting to a remote page to work, so I'll post my observation: The browser handles the redirect before your cookies are set.

Posted: Mon Oct 25, 2004 10:48 am
by mrclash
I see...and is there a general solution if the browser handles the redirect before the cookies are set??

Thanks :)