Cookies and headers not working
Posted: Fri May 31, 2002 5:55 am
just installed php 4.2.1 on WIN 2000 and IIS5 and I cant get cookies to work?
Have tried with Apache and php version 4.0.6 auto install and manual configuration.
Having trouble with the header() aswell. This code from Pro PHP4 book makes the browser time out. Yes cookies work in my browser and ive tried IE and Opera.
Have tried with Apache and php version 4.0.6 auto install and manual configuration.
Code: Select all
<?php $accesses++; setcookie("accesses", $accesses);
?>Code: Select all
<?php
// check for cookies with the algorithm:
// 1 – Send a cookie
// 2 – Reload the page
// 3 – Check to see if the cookie exists
// 4 – Perform desired action based on the results
if (!$cookie) {
// Send a redirect header to the page proving that
// we’ve attempted to set the cookie.
header("Location: $PHP_SELF?cookie=1");
// Set a test cookie.
setcookie("test", "1");
} else {
// Test to see if the cookie hasn’t been set
if (!$test) {
// The cookie doesn’t exist
echo ("Please enable cookies in your browser.");
} else {
// The cookie exists, send them to a page with cookie support.
header("Location: http://yourserver.com/next.php");
}
}
?>