Welcome to WebmasterWorld Guest from 54.221.30.139

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php cookie error with header("Location: ...")

cookie gets to client box, but isn't read properly or something

     

jeremy goodrich

5:34 pm on Aug 8, 2001 (gmt 0)

WebmasterWorld Senior Member jeremy_goodrich is a WebmasterWorld Top Contributor of All Time 10+ Year Member




<?php
if( !(isset($Authenticate)))
{
header("Location: [client-url-here.com...]
exit;
}
?>

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 ;)

sugarkane

10:05 pm on Aug 8, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm... what code are you using to set (or not) $Authenticate ?

toadhall

6:48 am on Aug 9, 2001 (gmt 0)

10+ Year Member



Too many parentheses. Try:

<?php
if !(isset($Authenticate))
{
header("Location: [client-url-here.com...]
exit;
}
?>

jeremy goodrich

11:59 am on Aug 9, 2001 (gmt 0)

WebmasterWorld Senior Member jeremy_goodrich is a WebmasterWorld Top Contributor of All Time 10+ Year Member



hmmm...still isn't working quite right. Here is the relevant portion of the script which assigns the cookie to the browser:

<?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.

sugarkane

1:00 pm on Aug 9, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's pretty wierd, it works perfectly here...

------
<?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...

jeremy goodrich

2:01 pm on Aug 9, 2001 (gmt 0)

WebmasterWorld Senior Member jeremy_goodrich is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Thanks! I think the setcookie() extra parameters did the trick...for some reason, it wasn't recognizing the cookie from "www.client-url-here.com" but only "client-url-here.com" without the www. Strange.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month