Problem to set a cookie

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zek2005

    #1

    Problem to set a cookie

    Hi!

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

    setcookie("usNi ck",$nickN,time ()+7776000);
    setcookie("usPa ss",$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_COO KIE_VARS["usPass"]))
    {
    $result = mysql_query("SE LECT * FROM usuarios WHERE nick='".
    $HTTP_COOKIE_VA RS["usNick"]."' AND password='".
    $HTTP_COOKIE_VA RS["usPass"]."'");
    }
    else
    {
    setcookie("usNi ck","x",time( )-3600);
    setcookie("usPa ss","x",time( )-3600);
    }

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

    Regards,

    Ezequiel

  • Rik

    #2
    Re: Problem to set a cookie

    zek2005 <esapoznik@gmai l.comwrote:
    Hi!
    >
    I validate a user and set a cookie woht the following sentence:
    >
    setcookie("usNi ck",$nickN,time ()+7776000);
    setcookie("usPa ss",$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_COO KIE_VARS["usPass"]))
    {
    $result = mysql_query("SE LECT * FROM usuarios WHERE nick='".
    $HTTP_COOKIE_VA RS["usNick"]."' AND password='".
    $HTTP_COOKIE_VA RS["usPass"]."'");
    }
    else
    {
    setcookie("usNi ck","x",time( )-3600);
    setcookie("usPa ss","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

    Comment

    Working...