Jump to content

Change 'that' link everyday automatically


Norman
 Share

Recommended Posts

I was asking myself if is possible to have a 'random link'. I mean, I have a button called "Images and random pages" and when I click on it everyday, it changes link -> 1December: image.gif, 2December: image2.gif, 3December: htmlpage.htm, 4December: image7.gif, etc. Is this possible?

Link to comment
Share on other sites

However you want to do it, really. You could have a big list of things and generate a random number to pick one, you could assign certain things to certain dates and look up the item for the current date, it just depends how you want to do it. You could store all the items to choose from in a database, or a file, or a hard-coded array, it's up to you.

Link to comment
Share on other sites

I want something simple. I want to do this:My buttom name: "Check It!".My folder where images are in: "checkit". Webpage: checkit.html(/php) [on this page I would like to have the script that calls the random image/content from the 'checkit' folder]. For example: in my checkit.php I have my standard content, and then, I have $checkit. It changes everyday.This. If possible, I would like to know wich PHP (I think) script should I use? Or maybe.. what words should I put on my Google navbar! :)

Link to comment
Share on other sites

You can use the mt_rand function to generate a random number, and you can use the readdir function to get the list of files in the directory. If you store the list of files in an array, then you can use mt_rand to generate a random array index, or you can use the array_rand function to just get a random element from the array. Check the documentation on php.net for those functions for more info.

Link to comment
Share on other sites

  • 4 months later...

I bump this thread becouse I've found this PHP script: This is exactly was I was searching for:

<?php/* * Name your images 1.jpg, 2.jpg etc. * * Add this line to your page where you want the images to  * appear: <?php include "randomimage.php"; ?> */ // Change this to the total number of images in the folder$total = "11";// Change to the type of files to use eg. .jpg or .gif$file_type = ".jpg";// Change to the location of the folder containing the images$image_folder = "images/random";// You do not need to edit below this line$start = "1";$random = mt_rand($start, $total);$image_name = $random . $file_type;echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";?>

http://www.totallyphp.co.uk/scripts/random_image.htm :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...