Ok, here's the entire page.... What's happening is when the person logs in, the session variables are carried over... But the cookie variables aren't created until after I click something else.
I think it's because
if($COOKIE['authuser'])
{
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$authuser=$COOKIE['authuser'];
$cookiequery="SELECT * FROM passwords WHERE authuser='$authuser'";
$cookres=mysql_query($cookiequery);
$cookrow=mysql_fetch_array($cookres);
$cookpass=$cookrow['authpass'];
$authpass=$cookpass;
echo "Authuser: $authuser<br>Cookiequery: $cookiequery<br>Cookres: $cookres<br>Cookrow: $cookrow<br>Cookpass: $cookpass<br>Authpass: $authpass<br>";
}
needs to be somewhere else, but I'm not sure where to put it. I would like it so the cookie is created as soon as the person logs in with the correct login/password combo. Also, I want the page to check for the cookie and automatically log them in after it finds the cookie.
<?php
session_start();
$time= time()+60*60*24*30;
setcookie("authuser", $_SESSION['authuser'], $time);
if($_POST["authuser"])
{
$authuser=$_POST["authuser"];
$authpass=$_POST["authpass"];
}
elseif($_SESSION["authuser"])
{
$authuser=$_SESSION["authuser"];
$authpass=$_SESSION["authpass"];
}
/*$authuser=$_POST['authuser'];
$authpass=$_POST['authpass'];
*/
include("dbinfo.inc.php");
$submit=$_GET['submit'];
$sort=$_GET['sort'];
$order=$_GET['order'];
if(!$order){
$order="ASC";
}
if(!$sort){
$sort="firstname";
}
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if($_COOKIE['authuser'])
{
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$authuser=$_COOKIE['authuser'];
$cookiequery="SELECT * FROM passwords WHERE authuser='$authuser'";
$cookres=mysql_query($cookiequery);
$cookrow=mysql_fetch_array($cookres);
$cookpass=$cookrow['authpass'];
$authpass=$cookpass;
echo "Authuser: $authuser<br>Cookiequery: $cookiequery<br>Cookres: $cookres<br>Cookrow: $cookrow<br>Cookpass: $cookpass<br>Authpass: $authpass<br>";
}
$_SESSION['authuser']=$authuser;
$_SESSION['authpass']=$authpass;
$query="SELECT * FROM contest ORDER BY $sort $order";
$result=mysql_query($query);
$num=mysql_numrows($result);
$querypass="SELECT * FROM passwords WHERE authuser='$authuser' AND authpass='$authpass'";
$resultpass=mysql_query($querypass);
$numpass=mysql_num_rows($resultpass);
mysql_close();
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link href="../linksnew.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {font-size: 14px}
.style2 {
color: #ff0000;
font-weight: bold;
}
.style3 {color: #cc0000}
-->
</style>
<? if($numpass=="1"){ ?>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
</tr>
<tr>
<td valign="top"><br>
<div align="center" class="style1"><span class="style2">Current Contestant List</span><br>
<br>
</div></td>
</tr>
<tr>
<td valign="top">
<form name="form1" method="GET" action="contest_results.php">
<select name="sort" size="1">
<option value="">Select
<option value="firstname">First Name
<option value="lastname">Last Name
<option value="email">E-Mail
<option value="age">Age
<option value="entrydate">Date Entered
</select>
<input name="Submit" type="submit" class="redform" value="Order List">
</form>
<div align="center"><a href="logout.php">Logout</a></div>
</td>
</tr>
<tr>
<td valign="top">
<? echo " Sorting by $sort. <a href=\"contest_results.php?sort=$sort&order=ASC\" title=\"Sort ascending.\"><img src=\"../graphics/nav_buttons/up_cc0000.gif\" width=\"10\" height=\"10\" border=0></a> <a href=\"contest_results.php?sort=$sort&order=DESC\" title=\"Sort descending.\"><img src=\"../graphics/nav_buttons/down_cc0000.gif\" width=\"10\" height=\"10\" border=0></a>"?>
</td>
</tr>
<tr>
<td valign="bottom">
<img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
</tr>
<td>
<table align="left" width="350" border="0" cellspacing="0" cellpadding="0">
<?
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"firstname");
$namelast=mysql_result($result,$i,"lastname");
$address_1=mysql_result($result,$i,"address_1");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$country=mysql_result($result,$i,"country");
$phone=mysql_result($result,$i,"phone_number");
$email=mysql_result($result,$i,"email");
$zip=mysql_result($result,$i,"zip");
$age=mysql_result($result,$i,"age");
$comments=mysql_result($result,$i,"comments");
$entrydate=mysql_result($result,$i,"entrydate");
$id=mysql_result($result,$i,"ID");
?>
<tr>
<td rowspan="3" background="../graphics/bkgd/1px_333.gif"><img src="../graphics/bkgd/1px_trans.gif" width="10" height="100%"></td>
<td><img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
<td rowspan="3" background="../graphics/bkgd/1px_333.gif"><img src="../graphics/bkgd/1px_trans.gif" width="10" height="100%"></td>
</tr>
<tr>
<td width="330" bgcolor="#666666">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="95%">
<?php echo "$name $namelast - ";
if(!$age){
echo "Did not give age information.<br>";
}
else{
echo "$age years old.<br>";
}
echo "Entered $entrydate.<br><br>$address_1<br>$city, $state $zip<br>$phone<br><a href=\"mailto:$email\">$email</a>"?>
</td>
</tr>
<tr>
<td>
<? echo"<div class=\"whitetiny\"><strong>Comments</strong></div>$comments" ?>
</td>
</tr>
</table></td>
</tr>
<tr>
<td>
<img src="../graphics/bkgd/1px_333.gif" width="100%" height="5"></td>
</tr>
<?
++$i;
}
?>
</table>
</td>
</tr>
</table>
<br>
<? }
elseif(!$authuser || !$authpass){?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php"><table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="50%">
<div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form>
<? }
elseif($numpass=="0"){?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td colspan="2">Something was entered incorrectly... </td>
</tr>
<tr>
<td width="50%"><div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form>
<? }
else{?>
<br><br><br>
<form name="form2" method="POST" action="contest_results.php">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#666666">
<tr>
<td width="50%" height="26"><div align="right">Username</div></td>
<td><input name="authuser" type="text" id="authuser" size="23" maxlength="23"></td>
</tr>
<tr>
<td colspan="2"><img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="authpass" type="password" id="authpass" size="25" maxlength="25"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" class="redform" value="Submit">
<input name="Reset" type="reset" class="redform" value="Reset">
<img src="../graphics/bkgd/1px_trans.gif" width="100%" height="5"> </div></td>
</tr>
</table>
</form>
<? }
?>