...

View Full Version : Cookie problems



drdysdy
02-28-2005, 04:42 PM
<?php

include "dbinfo.inc.php";


// Find out the username and password stored in the db
$sql = "SELECT `username`, `password`, `user_id` FROM `users` WHERE `username` = '$UnFromForm'";
$result = mysql_query( $sql );

while ($row = mysql_fetch_array( $result )) {
$UnInDb = $row['username']; //UserName in the Database
$PwInDb = $row['password']; //Password in the Database
$userid = $row['user_id'];
}


// Find out if this page is checking UN/PW or asking for UN/PW
if (isset( $_POST['submit'] )) { // If it is checking UN/PW
// See if the username entered on the form matches the one in the db
if( ($PwFromForm==$PwInDb) && ($UnFromForm == $UnInDb)) {
// Success
setcookie( 'loggedon', 'true', time()+60*60*24*30, '/', '**.**.**.**', 0 );
setcookie( 'username', $UnInDb, time()+60*60*24*30, '/', '**.**.**.**', 0 );
setcookie( 'userid', $userid, time()+60*60*24*30, '/', '**.**.**.**', 0 );
begining();
}

else {
// Failure
?>
Incorrect, Click <a href="logintest2.php">Here</a> To try again
<?
}
}
if (!isset( $_POST['submit'])) { // If there has not been a un/pw entered
// Check to see if the cookie is already there:
if(isset($_COOKIE['loggedon'])) {
begining();
}

else {
// Ask them for it

?>
<TABLE>
<FORM action="logintest2.php" method="POST">
<TR>
<TD>Username:</TD>
<TD><INPUT name="UnFromForm" type="TEXT" /></TD>
</TR>
<TR>
<TD>Password:</TD>
<TD><INPUT name="PwFromForm" type="PASSWORD" /></TD>
</TR>
<TR>
<TD><INPUT name="submit" type="submit" value="Log-On" /></TD>
</TR>
</FORM>
</TABLE>
<?
}
}
function begining() {
?>


<a href="logout2.php">Click here to log out</a><br>
<a href="space4.php">Click here to go to space</a><br>
<a href="notes.php">Post or Read notes</a>

<?
}


?>





For some reason the cookies arent being set and for the life of me i cant figure out why :mad:

marek_mar
02-28-2005, 06:27 PM
Did you read about the common pitfalls (http://www.php.net/set_cookie)?

drdysdy
03-01-2005, 12:11 AM
yea ive read the whole thing but still cant figure out why its not setting the cookies



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum