Forum Moderators: coopster
if(empty($testcookie)) { // Cookie is not set[/quote[ on this page... [forums.devshed.com...]Here is my code for those in the future who LIKE learning from repetive and EASY examples... :-)
Setting the cookie automatically when a user enters a certain page (set by JUST visiting that page)....
[quote]<?php setcookie("bandwidth","4",time()+2592000,"/");?>
That cookie has a name of "bandwidth" and the value that the cookie has set is "4". The time before it expires (1 month) is calculated 60x60x24x30 (60secs x 60mins x24hours x 30days). The last part of that cookie allows it to be used ANYWHERE on the domain. If you take it out it will ONLY work in the directory the cookie was set in.
Now later on if you need to say know what the bandwidth is or whatever other variable you've set you can do this...
<?php
if ($HTTP_COOKIE_VARS[bandwidth]=="0") {echo '0';)
elseif ($HTTP_COOKIE_VARS[bandwidth]=="1") {echo '1';)
elseif ($HTTP_COOKIE_VARS[bandwidth]=="2") {echo '2';)
elseif ($HTTP_COOKIE_VARS[bandwidth]=="3") {echo '3';)
elseif ($HTTP_COOKIE_VARS[bandwidth]=="4") {echo '4';)
elseif (empty($HTTP_COOKIE_VARS[bandwidth])) {echo 'DOH!';}
?>
In this case I will probally setup something to ask the person what their bandwidth is as my site is intended to ask that question when you enter.
For the curious there are 5 settings...
0 = Unknown / No Audio
1 = Dialup / No Audio
2 = Dialup / Yes Audio
3 = Broadband / No Audio
4 = Broadband / Yes Audio
Hope this helps people in the future! :-)
~ JAB