Page 1 of 1

Posting Cookies

Posted: Sat Mar 06, 2004 6:45 pm
by James138
My cookies on my site will not copy across the pages whatever I do. They are supposed to post to localhost/project/memberoptions/membersoptions.php. Anyone got any ideas as I am stuck!

<?php
require_once('../Connections/james.php');
function output_form ($error_message = '', $username = '')
{
print
'<html>
<head>
<p align="center"><title>Untitled Document</title>
<p align="center"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<align="center"><p><img src="../Templates/background1_r1_c1.gif" width="800" height="151"></p>
<center>
<form method="POST"
action = "http://localhost/project/Login Page/IndexMainpassword.php">
<p>Here you will be able to enter future competitions for your golf club online</p>
<p align="center">Welcome to Golf Competitions Online.<br>';
if ($error_message !='')
{
print '
<font color=green>' . $error_message . '</font>';
}

print '
<p align="center"> <br>Please enter your username and password below.
<br>
Username:<font color="#FFFFFF">::</font><input text type="text" size="20" maxlength="20" name="username"';

if ($username != '')
{
print ' value="' . $username . '"';
}

print '><br>
<p>Password: <input name="Password" text type="Password">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="Reset">

<br>
<p align="left">Administrator enter here. </p>
<p align="left"><a href="http://localhost/project/Login Page/AdministratorLogin.php">enter details page</a><br>
</p>
</form>
<br>
</center>
</body>
</html>';
}
//Javascript:alert(document.cookie);
mysql_select_db($database_james, $james);
if (isset($_POST['username']))
{
$sql = "SELECT password, memberID FROM membertable WHERE memberID ='$username' AND password = '$Password'";

$result = mysql_query($sql) or die("Error: Mysql error".mysql_error());

$num = mysql_num_rows($result);
$row = mysql_fetch_assoc($result);

if($num != 0)
{
setcookie ("user_name", $_POST['username']);
header("location: http://localhost/project/memberoptions/ ... ptions.php");
}
else
{
output_form ('Sorry hunny buns that was incorrect please try again');
}
}
else
{
output_form();
}
?>




Thanks!

Posted: Sun Mar 07, 2004 7:28 am
by tim
as you may not know, if you use the setcookie function and do not assign a time() value to it, it will delete soon after the browser closes.

try setting a time function to it.

Code: Select all

<?php
setcookie ("user_name", $_POST['username'], time()+3600); 
//the cookie will expire is exactly one hour
?>
the time function is in seconds (3,600 seconds in one hour)

cheers