PHP - How do i randomly display pictures - Asked By Olusegun A. on 08-Dec-09 03:17 PM

I want to use pictures as my CAPTCHA on my form page., i have all the pictures i want in my picture folder. is it possible or how do i display a different picture every time my form page is refreshed or visited?

If it is not possible, kindly recommend wayout.


regards

Javascript - F Cali replied to Olusegun A. on 08-Dec-09 03:41 PM

You can use javascript to display random images on your web page.  Here's a link to javascript that does that function:

http://www.java-scripts.net/javascripts/Random-Image-Script.phtml

All you have to do is provide the list of images you would want to display on your page and the javascript will take care of randomizing it.

Regards,
SQL Server Helper

Image load for CAPTCHA - Venkat K replied to Olusegun A. on 08-Dec-09 09:29 PM

Actually instead of loading random image. While implementing  CAPTCHA we usually display only a single plain image and add the text to that image randomly.

So here we will generate only text randomly:

Here is an excellent demo how can we generate a random string and show on image:

Complete example:

http://www.codewalkers.com/c/a/Miscellaneous/Creating-a-CAPTCHA-with-PHP/

Hope this helps!

Thanks,

randomly display pictures - mv ark replied to Olusegun A. on 09-Dec-09 04:53 AM
Rename image file names with sequential numbers. Use the rand function to generate a random number from a specified range - http://php.net/manual/en/function.rand.php

Use the random number to form a meaningful file path to show a random image each time.