Hi please can anybody tell me if it is possible to write a code in php that will change the image being display on my website every second. In others I want three different images to display at my homepage but at intervals. Thanks

You can't change anything about the page once it is loaded with PHP. It would require javascript to do that.

Javascript Image Rotator:
(not PHP)
Usage:
The switchtime is milliseconds to switch (at 5 seconds right now),
The images array is an array of images to be cycled through. They can be a relative or absolute path.

/*CodeJoust Javascript Imagerotator object. */
var imgRotator = {
init: function(el){
this.timeout = setTimeout(this.rotateImg(), this.switchtime);
this.el = el;
}
switchtime: 5000,
timeout: false,
number: 0,
el: false,
images: ['img1.jpg','img2.jpg','img3.jpg'],
rotateImg: function(){
if (!this.images[this.number+1]) { this.number = this.number+1; }
else { this.number = 0; }
this.el.src = this.images[this.number];
}
};
<img onload="imgRotator.init(this)" src="initalimg.jpg" />

^that would be the javascript I was talking about :P

Thanks for the reply, how can I insert the code into my php to make it run when the homepage is being display. Can I use

include_once('filename.js');

No, use

<script type="text/javascript" src="image.js"></script>

instead.
It's cleaner.

Thanks very much

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.