You are here: Re: Can't set cookies « All PHP « IT news, forums, messages
Re: Can't set cookies

Posted by Lee David on 06/15/05 06:01

OK, I guess this one was too difficult. I tried to simplify it by building
one of these for each page so I don't have to call the $_REQUEST variable to
see who invoked the page. Still didn't work.

I read in the manual that you can't have any "white space" before the set
cookie function so I put in comments on ever line so none of them are "white
space" and that didn't work. For some reason I can't write cookies. Here
is the code:

<?php
if (isset($_POST["id"]))
{
// page redisplayed with results of this code
$user = "me";
$pwrd = "mypassword";
$cont = "localhost";
$name_db = "mokenabarber";
$name_table = "UserID";
// form variables
$time = date("Y-m-d h:m:s", time());
$id = $_POST["id"];
$pwd = $_POST["pwd"];
// set SQL session
$name_connect = mysql_connect($cont, $user, $pwrd) or die(mysql_error());
$db_connect = mysql_select_db($name_db, $name_connect) or
die(mysql_error());
// set SQL call
$sql_code = "SELECT Password, Level FROM $name_table ";
$sql_code .= "WHERE ID = '$id'";
// testing only
// echo $sql_code . "<br><br>";
// check SQL output
$sql_result = mysql_query($sql_code,$name_connect) or die(mysql_error());
$output = mysql_fetch_array($sql_result);
// testing only
// echo mysql_result($sql_result,0,0) . "<br><br>" .
mysql_result($sql_result,0,1) . "<br><br>" . mysql_num_rows($sql_result) .
"<br><br>cookie: " . $pwd . "<br><br>act: " . $act . "<br><br>";
// store database variables
$pwdSQL = $output["Password"];
$lvlSQL = $output["Level"];
// set cookie time limit - 180 days
$hold = 60 * 60 * 24 * 180;
if ($pwdSQL == $pwd)
{
// validated user - write cookie and continue
setcookie("user", $id, $hold);
setcookie("level", $lvlSQL, $hold);
setcookie("authorized", "yes", $hold);
header("Location: http://www.mokenahickorycreek.com/SQL_Staff.php");
exit;
}
else
{
setcookie("user", "guest", $hold);
setcookie("level", "0", $hold);
setcookie("authorized", "no", $hold);
header("Location: http://www.mokenahickorycreek.com/index.php");
exit;
}
}

?>

Of course, you have to have the $_POST variable set to get to the code. It
is set in the form:

<form method="post" action="SQL_Staff_Validate.php">
<input name="postaction" type="hidden" value="validateuser">
<table align="left" width="100%" align="center">
<tr>
<td align="right">
User ID:</td>
<td>
<input name="id" type="text" size="20" value="<?php echo $_POST[id]?>">
</td></tr>
<tr>
<td align="right">
Password:</td>
<td>
<input name="pwd" type="password" size="10" value="<?php echo
$_POST[pwd]?>">
</td></tr>
<tr>
<td colspan="2" align="center">
<br><br>
<input name="submit" type="submit"><br><br>
</td></tr>
<tr>
<td colspan="2" align="center">
<br><br>
Called from
<?php
// testing
echo "testing: SQL p/l: '" . $pwdSQL . "' '" . $lvlSQL . "'<br>";
echo " p/l: '" . $pwd . "' '" . $lvl . "'<br>";
echo "Post id: '" . $id . "'<br>";
?>
<br><br>
</td></tr>
</table>
</form>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация