NYCPHP Meetup

NYPHP.org

[nycphp-talk] why does setcookie fail?????

Patrick Hunt pat at vote.com
Sat Sep 6 16:34:36 EDT 2003


for 

 header("Set-Cookie:nordicnet_registration={"
.$row['nnet_user_registrationnumber'] . "}; path=/");

I see 2 things:

1. Do you want the value wrapped in curly braces? If not, it should
be either:


header("Set-Cookie:nordicnet_registration={$row['nnet_user_registrat
ionnumber']}; path=/");
   or 
 header("Set-Cookie:nordicnet_registration="
.$row['nnet_user_registrationnumber'] . "; path=/");


2. I suspect the real problem is that
$row['nnet_user_registrationnumber'] is null. That would definitely
make the browser discard the cookie.



--Original Message Text---
From: Phil Powell
Date: Sat, 6 Sep 2003 16:28:50 -0400

here 
again:

<?


require_once('/home/nordicnet.no/include/nordicnet_global_vars_funct
ions.php
');

  $html = ''; // TO USE FOR DISPLAY UPON SUCCESSFUL LOGIN OR
OTHERWISE IS
BLANK

  // OPEN DB CONNECTION IF hasLoggedIn IS TRUE
  if ($hasLoggedIn) {
   $dbConn = mysql_connect($dbServer, $dbUsername, $dbPassword) or
die('Could not connect to db server');
   if (!mysql_select_db($dbName, $dbConn)) die('Could not select
db')
}


/*------------------------------------------------------------------
--------
-----------------
    Server-side validation block - check for username and password
in db and
return results
    back - if true redirect to Palogget%20S1.php, otherwise, stay
here and
prompt for correct
    username/password
 
--------------------------------------------------------------------
------
------------------*/
  if ($hasLoggedIn && strlen($brukernavn) == 0) {
   $hasLoggedIn = 0;
   $errorMsg .= $font . '<font color=cc0000><li>Skikka din
brukernavn,
takk!</li></font></font><p>';
  }

  if ($hasLoggedIn && strlen($passord) == 0) {
   $hasLoggedIn = 0;
   $errorMsg .= $font . '<font color=cc0000><li>Skikka din passord,
takk!</li></font></font><p>';
  }

  if ($hasLoggedIn) {
   $sql = 'SELECT nnet_user_registrationnumber FROM
nnet_usermetadata ' .
          'WHERE nnet_username = \'' . $brukernavn . '\' ' .
          ' AND nnet_password = \'' . $passord . '\' ';
   $query = mysql_query($sql) or die('Could not perform query');
   if (mysql_num_rows($query) == 0) {
    $hasLoggedIn = 0;
    $errorMsg .= $font . '<font color=cc0000><li>Vi kann ikke tykka
brukernavnen eller passorden '.
                 ' inn v&#229;r db</li></font></font><p>';
   }
  }
  //---END OF SERVER-SIDE VALIDATION
BLOCK-------------------------------------------------------------


  // IF hasLoggedIn IS STILL TRUE WE FOUND THEIR LOGIN INFORMATION
- CLOSE
UP, SET COOKIE AND REDIRECT
  if ($hasLoggedIn && ($row = mysql_fetch_row($query))) {
   setcookie('nordicnet_registration',
"$row['nnet_user_registrationnumber']", 0, '/');
   //header("Set-Cookie:nordicnet_registration={" .
$row['nnet_user_registrationnumber'] . "}; path=/");
   @mysql_free_result($query);
   mysql_close($dbConn) or die('Could not close db');
   $html .= $font . '<font color=000099>Takk for logging inn.  For
forsatte
' .
            "<a href=/membersites/Palogget%20S1.php
target=_top>klikk
her</a></font></font>";
  } else if (sizeof($_POST) > 0) {
   $errorMsg .= $font . '<font color=cc0000><li>Det finns en
problem med
db</li></font></font><p>';
   $hasLoggedIn = 0;
  }

?>

: Logg inn Logg inn til  " onSubmit="return isValidLogin()"> -
Obligatoriske felt  Brukernavn:  0) echo " value=\"$brukernavn\"";
?>> Passord:  Glemt du din passord? Klikk her 

Phil
----- Original Message ----- 
From: "Brian Pang" <bpang at bpang.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Saturday, September 06, 2003 4:23 PM
Subject: Re: [nycphp-talk] why does setcookie fail?????


> umm, with this piece of code the only instance of setcookie that I see
> is commented out
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk

_______________________________________________
talk mailing list
talk at lists.nyphp.org
http://lists.nyphp.org/mailman/listinfo/talk


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030906/f2d5ef55/attachment.html>


More information about the talk mailing list