I created this simple script which will either set a cookie with three values or retrieve the cookies values if they are already set. On my server running PHP4, everything works. On my server with PHP 5 (5.2.11), the script fails to set the cookie in the browser. I already checked if output buffering is enabled in my php.ini and it is. Does anyone have any ideas as to why this fails to work?
<?php
echo "<!DOCTYPE html>";
echo "<body>";
if (!isset($_COOKIE['taeinv'])) {
echo "No cookie set... Attempting to set a new cookie.";
$user = "testuser";
$role = "admin";
$expire = "true";
$halfHour = 1800;
setcookie("websitename[Expire]", $expire, time()+$halfHour);
setcookie("websitename[User]", $user, time()+$halfHour);
setcookie("websitename[Role]", $role, time()+$halfHour);
}
if (isset($_COOKIE['websitename'])) {
echo "Cookie Values:";
echo "<br />";
foreach ($_COOKIE['websitename'] as $name => $value) {
echo "<b>$name</b> : $value <br />\n";
}
}
echo "<br />";
echo "<a href=logout.php>Logout</a>";
echo "</body>";
echo "</html>";
?>