NYCPHP Meetup

NYPHP.org

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

Phil Powell soazine at erols.com
Sat Sep 6 16:08:05 EDT 2003


I closed and reopened my browser to refresh settings, and then I go to
logginn.php to log in.  I don't know what other line of code is running, but
at this point I'm going to just totally violate protocol and dump the entire
script to you to see.

Phil

<?


require_once('/home/nordicnet.no/include/nordicnet_global_vars_functions.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;
  }

?>

<html>
<head>
<title><?= $brand ?>: Logg inn<? if ($hasLoggedIn) echo ' - Takk!';
?></title>
<link rel=stylesheet href=/stylesheets/nordicnet_style.css type=text/css>
</head>
<body><?

  if ($hasLoggedIn) {
   echo $html;
  } else {

?>

<script>
<!--

  function isValidLogin() {
   if (document.loginForm.brukernavn.value == "") {
    alert("Skikka din brukernavn, takk!");
    document.loginForm.brukernavn.focus();
    return false;
   } else if (document.loginForm.passord.value == "") {
    alert("Skikka din passord, takk!");
    document.loginForm.passord.focus();
    return false;
   }
  }

//-->
</script>
<?= $font ?>Logg inn til <?= $brand ?></font><?= $errorMsg ?>
<form name=loginForm method=post action="<?= $PHP_SELF ?>" onSubmit="return
isValidLogin()">
<div align=center>
<table border=0>
 <tr>
  <td colspan=2><?= $font . $req ?> - Obligatoriske felt</font></td>
 </tr>
 <tr>
  <td><?= $font . $req ?>Brukernavn:</font></td>
  <td><input name=brukernavn size=50 maxlength=255<?

   if (strlen($errorMsg) > 0) echo " value=\"$brukernavn\"";

?>></td>
 </tr>
 <tr>
  <td><?= $font . $req ?>Passord:</font></td>
  <td><input type=password name=passord size=50 maxlength=255></td>
 </tr>
 <tr>
  <td colspan=2><input type=submit name=skikka value="Logg inn"
class="blue_button"></td>
 </tr>
 <tr>
  <td colspan=2>
   <?= $font ?>Glemt du din passord? <a href=glemt_passord.php>Klikk
her</a></font>
  </td>
 </tr>
</table>
<input type=hidden name=hasLoggedIn value=1><?=
$_COOKIE['nordicnet_registration'] ?>
</form>
<?
  } // END OF CONDITIONAL TO DISPLAY LOGIN FORM IF NOT YET LOGGED IN

?>
</body>
</html>
----- Original Message ----- 
From: "Patrick Hunt" <pat at vote.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Saturday, September 06, 2003 3:52 PM
Subject: Re: [nycphp-talk] why does setcookie fail?????


> Phil,
>
> when I follow your login instructions I get the following header
> back from the login:
>
> HTTP/1.1 200 OK
> Date: Sat, 06 Sep 2003 19:44:59 GMT
> Server: Apache/1.3.27 (Unix) PHP/4.3.0 mod_gzip/1.3.19.1a
> FrontPage/5.0.2.2510 mod_layout/3.2
> X-Powered-By: PHP/4.3.0
> Set-Cookie: nordicnet_registration=deleted; expires=Fri,
> 06-Sep-2002 19:44:58 GMT; path=/
> Connection: close
> Content-Type: text/html
>
> I think a different line of code is executing, cuz there's a date
> there, and it's a year old, which explains why it's not taking.
>
> Pat
>
> -------------------------------
>
> On Sat, 6 Sep 2003 15:25:02 -0400, Phil Powell wrote:
>
> >http://www.nordicnet.no go to "Logg inn" and enter this username and
> >password:
> >
> >ppowell100001
> >6vKYtEwM
> >
> >You should see a text with link, click onto the link and then either
you'll
> >go to the right URL or to logginn.php again (the WRONG URL!)
> >
> >Phil
> >----- Original Message ----- 
> >From: "Brian Pang" <bpang at bpang.com>
> >To: "NYPHP Talk" <talk at lists.nyphp.org>
> >Sent: Saturday, September 06, 2003 3:22 PM
> >Subject: Re: [nycphp-talk] why does setcookie fail?????
> >
> >
> >> Phil, can you send me your url so I can try it in my browser?
> >>
> >> I maintain my recommendation that you should quote the cookie value you
> >> wish to set.
> >>
> >> setcookie('nordicnet_registration',
> >> "$row['nnet_user_registrationnumber']", 0, '/');
> >>
> >>
> >> > This is a multi-part message in MIME format.
> >> >
> >> >
> >> > Fourth attempt.. it fails now in login, I check by printing
> >> $_COOKIE['nordicnet_registration'] and there is no value there!  Guys,
> >> what on earth do I do about this????
> >> >
> >> > Here is the code that sets the cookie:
> >> >
> >> > if ($hasLoggedIn && ($row = mysql_fetch_row($query))) {
> >> >    setcookie('nordicnet_registration',
> >> $row['nnet_user_registrationnumber'], 0, '/');
> >> >    @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=http://$serverName/index.php?content=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;
> >> >   }
> >> >
> >> >
> >> > Because the PHP script is in a frame, instead of using header() I
> >> print out some text with a link <a href=mylink.php target=_top> for the
> >> user to click and to go to another page.  By then the cookie should be
> >> registered, yet it's not there!
> >> >
> >> > I'm at a complete loss.
> >> >
> >> > Phil
> >> >
> >>
> >>
> >>
> >> _______________________________________________
> >> 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
> >
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk




More information about the talk mailing list