Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i set a cookie and afterwards use a header? 1

Status
Not open for further replies.

KBBJ

Programmer
Jun 30, 2001
62
DK
<?php
setcookie(&quot;cookie&quot;,&quot;something&quot;);
header(”Location: http//?>

A little amateur-question: How can I get this tiny script to work?

I think it has something to do with:
ob_start()
...
ob_end_flush()

...But it just fails for me.

From KBBJ (-:
 
I have tried your code now(thanks for trying Sleidia).
Well. With your code, I will get relocated to a new site without problems, but the cookie is not created.

If I delete the; HEAD(LOCATION: etc.), the cookie will be created when a new site manually is loaded.

Is it just me or...

From KBBJ (-:
 
You have encouraged me to carry on with the problem Sleidia.
I figured out, that the code that works for you is a problem for me because there is a bug in PHP version 4.2.0. I have to turn DISPLAY_LOG_ERRORS off in php.ini before it works.

But it still don't work.

Instead I have my own solution in good old HTML:

<?php
ob_start();
setcookie(&quot;cook_log&quot;,&quot;something&quot;);
ob_end_flush();
echo '<META HTTP-EQUIV=&quot;refresh&quot; CONTENT=&quot;0;url=http://www.somewhere.com&quot;>';
?>

It's not pretty but it works.

Any suggestions will be granted.

From KBBJ (-:
 
This is a bug with iis. Don't use IIS, d/l apache or something. You can also set the cookie and redirect with javascript, just not set the cookie and redirect with the header, it drops the cookie in iis.
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top