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
mrclash
Forum Newbie
Posts: 4 Joined: Sat Oct 09, 2004 9:48 am
Location: Barcelona, Spain
Post
by mrclash » Sat Oct 09, 2004 10:04 am
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
Thanx.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Oct 09, 2004 10:13 am
the cookie setting may not happen before your browser redirects. Are you sure they are setting in the first place?
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Sat Oct 09, 2004 11:27 am
Which webserver and version are you using? Some have issues with this.
Mac
mrclash
Forum Newbie
Posts: 4 Joined: Sat Oct 09, 2004 9:48 am
Location: Barcelona, Spain
Post
by mrclash » Sun Oct 10, 2004 8:58 am
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 10, 2004 10:11 am
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.
mrclash
Forum Newbie
Posts: 4 Joined: Sat Oct 09, 2004 9:48 am
Location: Barcelona, Spain
Post
by mrclash » Mon Oct 11, 2004 6:27 am
You can try it at
http://www.mans-hq.net/igrafic/admin/signin.php .
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Oct 17, 2004 5:42 pm
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.
mrclash
Forum Newbie
Posts: 4 Joined: Sat Oct 09, 2004 9:48 am
Location: Barcelona, Spain
Post
by mrclash » Mon Oct 25, 2004 10:48 am
I see...and is there a general solution if the browser handles the redirect before the cookies are set??
Thanks