
November 7th, 2002, 04:31 AM
|
|
The calm b4 the storm
|
|
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404
Time spent in forums: < 1 sec
Reputation Power: 7
|
|
cookie problem...
hey everyone...
I have a login script (see below) which checks for the username and password stored in a text file.. eg: (username  assoword). ... that all works perfectly, and if a match is made, it will redirect the user to the admin.php
the problem is, it's not setting the cookie at all! I've tried a test page, so the cookie script is right... but for some reason it is just not being set. Is there something wrong with the code? or is the cookie in the wrong place??
Cheers for any help....
PHP Code:
<?php
//do_login.php
//this will check the username and password supplied from the login form
//and check the details against those found in the "users.txt" file.
//read in the contents of the file to get all users/passwords
$filename = "users.txt";
$fp = fopen($filename, "r");
$file_contents = fread($fp, filesize($filename));
fclose($fp);
//seperate the file by carriage returns
$line = explode("\r", $file_contents);
// loop for as long as $line has stuff in it
$a = 0;
$lineCount = sizeof($line);
while($a <= ($lineCount)) {
// explode to get username and password
$data_pair = explode(":", $line[$a]);
$username = trim($data_pair[0]);
$password = trim($data_pair[1]);
// try to find a match
if (($username == $user) && ($password == $pass)) {
//set login cookies
setcookie("auth","ok",time()+3600);
//located once I know the cookie is working!!
//header("Location: ../../admin.php");
//output the cookies..
foreach($_COOKIE as $key=>$value)
echo "$key: $value<br>\n";
break;
// if match doesn't exit, assign value of 0 to $auth
} else {
echo "no such username";
break;
}
// increment to continue looping
$a++;
}
?>
|