Web Hosting Talk







View Full Version : PHP + Cookie --- Setting & Changing Default Background of Site.


dpny
06-17-2004, 08:57 PM
Hi guys.. i need help with this please.

I have a php page that has a background tag on the body tag. How can I use cookie and set default background image to set as default.gif
and have a link somewhere from that page with "CHANGE BACKGROUND" when clicked will popup in a new window.. and show a drop down menu with choices of different color and when selected will go set the cookie and display a msg like "Next time you visit our site again, the changes will take place"

and then on the main php page, it first look for cookie.. and get the color_image.gif from the cookie and make it as the background of the page....

Burhan
06-18-2004, 06:59 AM
<?php

$background = @$_COOKIE['background'];
if ($background == "") { $background = "default.gif"; }

echo "<body background=\"$background\">";
?>


To set the cookie:

<?php
$background = $_GET['bg'];
setcookie("background",$background);
?>

Call the above like so setbackground.php?bg=background.gif

Obviously -- you will have to change it to fit your site. One thing I would change is not to pass the exact filename -- since its a big security problem. However, I will leave that as an exercise to you :)

dpny
06-18-2004, 05:08 PM
Fun-taste-it...
i meant fantastic :D
thanks so much ...

Now, how would I define the leanth of the cookie as I want to make it about 365 days long cookie.

Burhan
06-19-2004, 05:34 AM
See the setcookie manual (http://www.php.net/setcookie).