I'm trying to build a script to post news, and I want it to check to see if the user has logged in. Cookies are set at the login page.
I'm having trouble helping it recognize that I am cookied. What am I doing wrong?
This page, verify.php, checks the username/password and issues cookies if they are correct.
<?php
//variable contains data necessary to connect to mySQL.
$connect = mysql_pconnect("localhost", "mynameisbingo", "***") or die("Connect failed");
//variable contains data necessary to select the mySQL database.
$pickme = mysql_select_db("mynameisbingo_com") or die("Couldn't select database.");
$query = mysql_query("SELECT * FROM babusers WHERE uid='$uid' AND password='$password'");
$arows = mysql_num_rows($query);
$password = md5($password);
if($arows < 1) {
print "Incorrect. Please try again.";
}
elseif ($arows != 0) {
setcookie ("g_b_u_name", "$uid", time()+(60*60*24*15));
setcookie("g_b_p_name", "$password", time()+(60*60*24*15));
echo "You are now logged in.";
}
else {
print "Incorrect. Please retry.";
}
?>
This page is teh one that won't recognize cookies.
<html>
<head>
<?php
//variable contains data necessary to connect to mySQL.
$connect = mysql_pconnect("localhost", "mynameisbingo", "/***\
") or die("Connect failed");
//variable contains data necessary to select the mySQL database.
$pickme = mysql_select_db("mynameisbingo_com") or die("
Couldn't select database.");
if(!uid){
$uid = $_COOKIE['g_b_u_name'];
$password = $_COOKIE['g_b_p_name'];
}
$ius = isset($uid);
if ($ius == "0") {
print "You are not cookied. Please sign back in.";
exit;
}
?>
</head>
<body>
<form method="post" action="postedn.php">
Title: <input type=text name="title"><br><p>
Snippet: <textarea cols=60 rows=10 name="snip"></
textarea><p>
<p>
Story: <textarea cols=60 rows=20 name="story"></textarea><p>
<INPUT TYPE="SUBMIT" VALUE="Post this Story" ACTION="postedn
.php">
</form>
</html>
Any ideas?