homepage Welcome to WebmasterWorld Guest from 50.17.66.61
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php cookie error with header("Location: ...")
cookie gets to client box, but isn't read properly or something
jeremy goodrich

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



 
Msg#: 295 posted 5:34 pm on Aug 8, 2001 (gmt 0)


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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 295 posted 10:05 pm on Aug 8, 2001 (gmt 0)

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

toadhall

10+ Year Member



 
Msg#: 295 posted 6:48 am on Aug 9, 2001 (gmt 0)

Too many parentheses. Try:

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

jeremy goodrich

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



 
Msg#: 295 posted 11:59 am on Aug 9, 2001 (gmt 0)

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

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 295 posted 1:00 pm on Aug 9, 2001 (gmt 0)

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

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



 
Msg#: 295 posted 2:01 pm on Aug 9, 2001 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved