Hi, I wrote a script for a game where you need to identify what is pictured in a random image (you are presented with multiple choice options). I managed to make it pretty tough to cheat, but one problem remains: some of the images have the answer as their file names. For example if there were a pic of brittany spears, the file name on our server might be brit-spears.jpg. I know this shouldn't be too tough, but I'm having trouble figuring out how I can temporarily rename the image as something random so the user can't cheat by viewing source. Any code or links to code that can do this would be much appreciated. Some of the pics are gif and some jpeg, so I'm going to need to write something capable of handling both. Thanks
I would build a lookup in a table that maps a random string to the real filename. Then show the random filename.
THanks for the replies. Will check the link in a minute, but for jwalsh: forgive my ignorance but how would i map a random string to the real file name and have the code you see when clicking view > source not show the true file name?
In your database, you should have a unique ID for each row. If you also store the filename of the image in that table, you can lookup the ID to find the filename. For example, in your HTML you would put the image src as "image.php?id=5". The image.php script will lookup the corresponding real filename using WHERE id=5 for your database and output that image - you can do that with a content-type header and a readfile().
<img src="get_data.php" alt="strip" width="326" height="202"> in get_data.php Read contents for image file(fopen,fread,....) and print the contents.
Awesome, trying this now. Thanks again guys for the replies, gotta love DP. EDIT: Got it working. I ended up using the get_data.php concept with a variable like get_data.php?rand=1049925 and then within get_data.php I simply have header("Location: $photoURL"); As far as I can tell this is working perfectly..
Exactly, except we usually add a unique string separate from the ID. It's not necessary in this case though.
could you link to an image that doesnt exist, then use .htaccess to forward to the new image? then block the .htaccess file? just an idea
That's actually a really good question I'd be interested in hearing the answer to (or maybe I should not be lazy and just go test it)...