View Full Version : Turning DHTML into PHP???
08-19-2005, 11:33 AM
You know, sometimes I feel like an idiot... choose one language to learn and its never the right one.
I have a DHTML code that allows me to have "revolving" images show up in hourly time increments, say at noon one image is on the screen, and at 1 o'clock the image changes to another image.
This is a very nice effect, a great bit of code, very similar to the one found here:
The problem is with the application I want to use this in, hiding the picture name is vital. Otherwise the player could bypass the time limit and just view the other picture needed to complete the puzzle.
Is there a way to use php to have the same effect, and hide the picture names?
08-19-2005, 12:15 PM
Hmm. Interesting question.
I'll watch this thread for replies, and try to think of something myself.
At the moment, the best I can do is a concept:
- All the pages request the same "image", which will be a PHP file outputting an image.
- The PHP file gets the time from the server and sends the correct image through.
That way, all the filenames are the same, and it's the one PHP file that changes the image, not the image URL.
Tell me what you think.
08-20-2005, 11:39 AM
A few things:
1. It can't be completely PHP. However, you can use AJAX to help you along.
2. How are you going to store this list of images?
It can be completely PHP. AJAX isn't necessary. The GD library (or an equivalent), however, is.
08-20-2005, 07:18 PM
It can be completely PHP. AJAX isn't necessary.Assuming the OP isn't trying to push new images onto the client, but even then AJAX isn't necessary.
The GD library (or an equivalent), however, is.If the OP is just serving static images, the readfile function would be all that's necessary. Again, the OP hasn't specified.
Assuming the OP isn't trying to push new images onto the client, but even then AJAX isn't necessary.So why did you say that? :)
If the OP is just serving static images, the readfile function would be all that's necessary. Again, the OP hasn't specified.Yes, of course. I'm sorry, I sort of jumped to dynamic imagery.
08-20-2005, 09:17 PM
Assuming the OP isn't trying to push new images onto the client, but even then AJAX isn't necessary.So why did you say that? :)Well, if the OP does want to push images - that is, updating the image whilst the same page is displayed - then PHP cannot be used alone. However, AJAX doesn't need to be involved, just an assignment to the src property of the image.
In order to force a new request to the same resource, a random query string value can be appended to the URL:
img.src = 'image.php?' + (new Date()).getTime();Mike
08-21-2005, 02:01 AM
All those words and stuff above
HEE. Sorry, see if this will explain better. I have 2 static pictures. I want one picture to show up on the page from noon to midnight (for example) and the second image to REPLACE the first from midnight til noon. At which time the first picture would then replace the second.
This is for a game site, and it is important that the source code NOT give away the name of the pictures, or else the players could just put that name in the end of the URL, and view it. Also, I would prefer if it weren't known that there were multiple photos.
Hence the pure php question.
I am open to suggestions, hope this helps to clarify what I need. :)
if(date('G') < 12) $file = "beforenoon.png";
else $file = "aftermorning.png";
?>Thar y'go. Include the page in an HTML page just as you would any normal image.
However, AJAX doesn't need to be involved, just an assignment to the src property of the image.
Ah, you were referring to the "completely PHP" bit, not the AJAX bit. Sorry, my misinterpretation.
08-24-2005, 03:30 AM
Thank ye thank ye
Now I just have to wait 12 hours to make sure it works right :D
Or change the time on your server, or switch the < for an > :p
08-29-2005, 07:48 PM
so how would I write it if I have 2 pictures and wanted them to switch ever SIX hours instead of every 12?
I am guessing the server goes on a 24 hour clock, but I have no idea how to re-write the code to account for 6 hour increments.
$a = date('G');
if($a < 6) $file = "tooDarnedEarlyByFar.png";
else if($a < 12) $file = "early.png";
else if($a < 18) $file = "morning.png";
else $file = "daytime.png";
08-29-2005, 08:27 PM
Thanks Twey, you know... I almost did exactly that, and the only thing that kept me from doing it is that I have a couple of players that are currently on this level and I didn't want to screw anything up, lol.
You're the best.
Heh. You should have tested it in a seperate page, seen it worked, and overwritten the main page.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.