Hi all!

Your thoughts please on the following.

I have a php script to be run on the server every 10minutes or so.
Depending on some condition, I want an image at a particular url to change.
I then have a webpage in which a link is always pointing to that url.

In other words, how can I kind of swap images whilst retaining the same url on the server side in php?

thanks

Recommended Answers

All 5 Replies

Just to clarify, are you talking about the image changing while the user is on the page or when they come back to the page? The former would better handled in Javascript and to be honest, I'm not even sure PHP could do something like that since the code is executed once, on page load. If you are looking more towards the latter point, is there any particular order the image needs to show in or do you just want a random difference image every 10 minutes?

Thanks for your reply!

Let me try better explain what Im trying to achieve.I have a particular widget on my webpage which changes its image and some other css styles depending on whether a condition is true or not. This is done through some javascript in an xsl template which calls a php file (i.e. jquery.post) and depending on the returned value a particular css class is changed. This type of process occurs on every page refresh on every page where I have this widget.

so what I thought of was trying to do all this on the server side where I have a php script which is run every 10minutes (cron tab). This script checks for this particular condition (true of false), and depending on this particular condition the image at a particular url changes however the url is kept always the same. Then in my templates, I will always have the same url to that an image. This way there is no need to use a GET or POSt method every page refresh.

Point the image to a PHP file with the following code:

header('Content-Type: image/gif');
if($condition){
	readfile("true.gif");
}else{
	readfile("false.gif");
}

Of course that is for GIFs and you would change that out accordingly and in the header(); using media types.

thanks Alot! This worked well.

Now in my css it points to that php file which works great.
What I want to do now is use java script to detect the size of the image. In other words the image now changes on the server side...however I want to add some javascript and other css styles depending on that condition.

I believe you can do it by

document.getElementById(YOURIMAGE).clientWidth
document.getElementById(YOURIMAGE).clientHeight

More can be found here and here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.