Forum Moderators: coopster
I've got this in each of the files on the site. Trouble is, this is supposed to redirect only if the Authenicate cookie is not set...even after my browser is getting the cookie, it's not letting me have the page. Should I add an
else {
?>
<html> etc...</html>
<? } ?>
exit;
Something like, that, and encase the web page in an else statement?
Tips, etc would be most appreciated! Thanks. I'm amatuer, at best, in PHP lol...so explain slowly using small words ;)
<?php
if !(isset($Authenticate))
{
header("Location: [client-url-here.com...]
exit;
}
?>
<?php
$hostname = "localhost";
$usernamedb = "hmmm";
$passworddb = "hmmm";
$dbName = "hmm";
if($email && $password)
{#1
$db=mysql_connect($hostname, $usernamedb, $passworddb); mysql_select_db("$dbName", $db);
print mysql_error();
$query = "select * from ciao_list where email_id = '$email' and password = '$password'";
$result = mysql_query($query);
$value_row = mysql_num_rows($result);
if($value_row == 0)
{#2
echo"<B>Sorry</B>, unable to login <a href=\"../\">click here</a> try again";
exit;
}
else
{
$cookiestring = $email;
setcookie("Authenticate", $cookiestring, time()+5400);
header("Location: [clients-page.com...]
exit;
}
}
else
{
echo"Please enter all the fields";
}
?>
Thanks for the tips. This seems to work fine, because I can check my cookies in IE and see the cookie named "authenticate" there...but the other script above which is on each page, needs to know the cookie is there, before given away it's contents, else, redirect.
------
<?php
if (!isset($Authenticate)) {
header("Location:http://www.somehwere.else");
exit;
}
?>
Yup, we're cookied up...<br>
-----
The only thing I can suggest is to supply the other 3 optional arguments in setcookie() eg
setcookie("Authenticate", $cookiestring, time()+5400, "/path/", ".domain.com", 0);
It could be that there's some sort of misunderstanding between server and browser over the server's hostname, so spelling everything out might help.
Another long shot: does the PHP in your first post begin right at the top of your page? Whitespace will freak any header manipulations...