I currently have a cookie script that allowes me to set a background
on my website, assuming that all my file names look like this:
image1.jpg image2.jpg etc.. and you load them by going
index.php?setArt=1 . However I want to have different file names like
Hi-thisis_fun.gif HoWare-you-bob.jpg, etc... I basically just need a
setcookie script that lets me say setArt=iambob.jpg (i would actually
prefer that the .jpg part was not on the line but if that is what is
needed to allow different file extensions I understand.
I am currently using this script twice on my website to set different
images, I would like to use it another time to set css files, but I
would actually prefer to have 1 script that let me set 4 or 5
different things, so setArt, setCss, setBG, setColor, setOther....
This is not a requirement, but if you can do that to the script AND
get it to let me use any file names on the set line, I will give a
bonus on the answer.
I will include my current script, but feel free to paste your own if
you have one that works better as I am in no way attached to the
script, so long as I have a way to define the path to each variable in
the script, it will do the trick.
<?php
if (!empty($setart)) {
$art = $setart;
setArt();
} elseif (!empty($_COOKIE['art'])) {
$art = $_COOKIE['art'];
} elseif (!empty($diecookie)) {
dieCookie();
}
function setArt() {
global $art;
setcookie('art',$art,time()+2678500,'/','thesmartass.info');
}
function getArt() {
global $art;
$default_art = "random.php?pic=random1";
$image_dir = "./images/artwork/"; // trailing slash is important.
$image_path = "images/artwork/"; // here too.
$image_prefix = "image";
$image_suffix = ".jpg";
if (!empty($art)) {
$imagefile = $image_prefix.$art.$image_suffix;
if (!file_exists($image_dir.$imagefile)) {
$imagefile = $default_art;
}
} else {
$imagefile = $default_art;
}
return $image_path.$imagefile;
}
function dieCookie() {
setcookie('art','',time()-2678500);
}
?> |