|
-
Sep 7th, 2007, 01:59 PM
#1
Thread Starter
Lively Member
[Resolved] header faster than setcookie?
I've been wondering about this for some time now and now I need to have an answer for work.
When I write something like the following, the cookie doesn't get set:
Code:
<?
@setcookie("lister_id", $_GET['l'], time()+18144000, "/");
@header('Location: '.base64_decode($_GET['re']));
?>
But, when I replace PHP's header() with a client-side redirect the cookie gets set properly:
Code:
<?
@setcookie("lister_id", $_GET['l'], time()+18144000, "/");
echo '<script> document.location="'.base64_decode($_GET['re']).'"; </script>';
?>
The only thing I can think of is that since setcookie() has to deal with an actual file (the cookie on the client's machine) that the first command is not getting executed by the time the server gets to the header() command. Is that what's going on? Also, is there some way I can slow down this process so I don't have to incorporate a JavaScript redirect?
Many thanks.
Last edited by solitario; Sep 11th, 2007 at 09:19 AM.
Reason: sufficient answer
-
Sep 7th, 2007, 02:13 PM
#2
Re: header faster than setcookie?
PHP scripts are not multithreaded. It is impossible for the statements to be executed out of sync.
Remove the error-suppression operator (@) from both calls and then see what happens. Suppressing errors should never be done unless you have a very good reason.
I am not sure, but it might well be the case that browsers will not accept cookies set during a redirection.
-
Sep 7th, 2007, 02:56 PM
#3
Thread Starter
Lively Member
Re: header faster than setcookie?
Thanks penagate. I've written the code above many times without the error suppressor and still had the same problem. Perhaps your idea of browsers not accepting cookies on a redirect might be the case here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|