[nycphp-talk] why does setcookie fail?????
Phil Powell
soazine at erols.com
Sat Sep 6 16:28:50 EDT 2003
here it is again:
<?
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å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>
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
More information about the talk
mailing list