disabling an image.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

disabling an image.

Post by Daisy Cutter »

at my url http://kafene.org I have a random image on the left side. If anyone finds it irritating, i want to offer the ability to disable it via a cookie.

Could anyone help me?

I would prefer a link that reloaded the page with a cookie set to not display it, that would never expire, and when the cookie was present, a link to re-enable it. If you need page source just ask.

Thank you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What do you want help with? We aren't going to do it for you, at least not with this thread being in this forum. Do you have an idea of what code to write? Do you have any code you're working on for this?
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

well is it possible to make a link set a cookie? or does it need to be a form? I've done it once with forms, but that's it. I read some tutorials on cookies but im shaky on this, ie- I dont know the methods.

something like

Code: Select all

setcookie ("img", $img time()+7776000)
and then

Code: Select all

if (isset($_COOKIE["img"])) {
     *IMAGE CODE* }
else {}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.. that's the basics.. you'd just have them click a link that goes to a page that can either set or destroy the cookie. .. that's it. Then just make sure to check for it on the pages you want it to affect.. :?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Daisy Cutter wrote:something like

Code: Select all

setcookie ("img", $img time()+7776000)
if you didnt notice it, but you'll need another comma after the $var along with an ;

I know u probably are aware, but to save any future questions, plus I just want to be cool and act like I know what i'm talking about.

:P :P
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

Im testing this with a test page and getting an error because im trying to nest php code within more code I think...

and I cant figure out how to make it so after the cookie has been set you are returned to the main page.

wierd... a book I bought on php doesnt discuss cookies really at all.

EDIT:

okay if you go to http://kafene.org/php you can see you can make it say hello or not, using a cookie. i've got that down, one page to turn it on, one to turn it off.

I need help nesting code inside code (im sure theres an easy solution im missing here) and making it redirect to the last page once the cookie is set, or better, just refresh the page setting the cookie, like I've seen with javascript.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

How you could do it also:

instead of offering a link to the image directly, use a script with header location to redirect to the image url...

thus: <img src="script.php" />

----- script.php ---------
// lookup the $url to the image to display
header('Location: $url);
------------------------------------
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

I did it. I thought you couldnt set headers because the setcookie was like setting headers but I guess it isnt, because I did:

setcookie
then
header Location: $_SERVER['HTTP_REFERER']
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

setcookie does set headers.. but it doesn't send them. So you can add header calls in all you want as long as output hasn't started :)
Post Reply