By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,828 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,828 IT Pros & Developers. It's quick & easy.

Problem to set a cookie

P: n/a
Hi!

I validate a user and set a cookie woht the following sentence:

setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);

then I want to validate if the cookie is set with the following
sentence and it seems to enter in the "else", so the cookie was not
established.

if(isset($HTTP_COOKIE_VARS["usNick"]) &&
isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".
$HTTP_COOKIE_VARS["usNick"]."' AND password='".
$HTTP_COOKIE_VARS["usPass"]."'");
}
else
{
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}

Can anyone help me with this? I mena, setting the cookie correctly

Regards,

Ezequiel

Feb 4 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rik
zek2005 <es*******@gmail.comwrote:
Hi!

I validate a user and set a cookie woht the following sentence:

setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);

then I want to validate if the cookie is set with the following
sentence and it seems to enter in the "else", so the cookie was not
established.

if(isset($HTTP_COOKIE_VARS["usNick"]) &&
isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".
$HTTP_COOKIE_VARS["usNick"]."' AND password='".
$HTTP_COOKIE_VARS["usPass"]."'");
}
else
{
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}

Can anyone help me with this? I mena, setting the cookie correctly
First of all: never, never, never, never save a password in a cookie.
Second: use $_COOKIE.
Third: the cookie will only be set for future request, this request was
made without a cookie, so even if you set a cookie now it won't show up in
the $_COOKIE array automagically.

I suspect your more helped by just using sessions:
<http://www.php.net/session>
--
Rik Wasmus
Feb 4 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.