Posting Cookies

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
James138
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2004 1:41 pm

Posting Cookies

Post 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!
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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
Post Reply