1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Fast help with php scripting!

Discussion in 'PHP & Perl' started by Zoekban, Dec 14, 2014.

  1. Zoekban

    Zoekban Newbie

    Joined:
    Apr 23, 2013
    Messages:
    18
    Likes Received:
    0
    I've made recently a script for showing random pictures, The thing is that i want the script to show Random picture every specific time , like in 5 minutes, in 15 and in 30,
    How can it be done, And what do i need to add to my script to improve the script to be working by random timing?

    The script is being used in WordPress with the "allow php in post" plugin.

    The script is -


    $total = "2";
    $file_type = ".jpg";
    $image_folder = "(images source)";
    $start = "1";


    $random = mt_rand($start, $total);


    $image_name = $random . $file_type;


    echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";


    Thanks from ahead, And waiting for a reply and help.
    Thank you.

    Please post an answer with a source or an explanation, if it's possible, thank you!
     
  2. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    709
    Likes Received:
    267
    Location:
    PHP Scripting ;)
    Use time (). Store its value on the picture change. Check the current value of time () with the old one before changing the image again.

    Thats an easy way to do it.
     
  3. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    8,883
    Likes Received:
    7,478
    Occupation:
    ZLinky2Buy SEO Services
    Location:
    ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
    Home Page:
    There's this thing called Google. I just used it and it gave me 2.7 billion solutions to this question with actual PHP examples.
     
  4. mktanny

    mktanny Regular Member

    Joined:
    Oct 22, 2009
    Messages:
    225
    Likes Received:
    62
    Occupation:
    Blog editor and IM
    Code:
    $minutes = date('i');
    if($minutes<=15) {
    $total = "2";
    }elseif($minutes<=30){
    $total = "3";
    }
    $file_type = ".jpg";
    $image_folder = "(images source)";
    $start = "1";
    
    
    $random = mt_rand($start, $total);
    
    
    $image_name = $random . $file_type;
    
    
    echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\ />";
    Adjust the minutes according to your needs -- 15 ,30 .