PHP & JavaScript
Let JavaScript write the Cookie straight away !

... using just   PHP   cookie will affect the page from next visit !

<?
$bgcolor=$HTTP_COOKIE_VARS['bgcolor'];
if ($HTTP_POST_VARS['bgcolor'])
{setcookie('bgcolor', $HTTP_POST_VARS['bgcolor'], time()+(60*60*24*7)); }
else {$bgcolor=$HTTP_COOKIE_VARS['bgcolor'];}
echo"
<html><head><title>bgColor</title></head><body>

   <script language=javascript>
function getCookie(NameOfCookie)
{if (document.cookie.length > 0)
{start = document.cookie.indexOf(NameOfCookie+'=');
if (start != -1){start += NameOfCookie.length+1;
end = document.cookie.indexOf(';', start);
if (end == -1){end = document.cookie.length}
return unescape(document.cookie.substring(start, end)); }}
return 'aqua'; }
if(document.cookie=='')
{document.cookie='bgcolor=aqua';
document.write('<body bgcolor=aqua>')};
document.write('<body bgcolor = '+getCookie('bgcolor')+'>');
document.write('<form name=mf method=POST>');
document.write('<select name=bgcolor>');
          document.write('<option value=aqua>Aqua');
          document.write('<option value=red>Red</option>');
          document.write('<option value=green>Green</option>');
          document.write('<option value=blue>Blue</option>');
          document.write('</select> <input type=submit></form>');
          document.forms.mf.bgcolor.value=getCookie ('bgcolor');  
   </script>

";
?>

<script language=javascript>
document.write('<body bgColor='+getCookie('bgcolor')+'>');
</script>
</body> </html>
home