user1365447
user1365447

Reputation: 145

Duplicate images with image placeholder services?

I have a little problem with duplicate images filled by placeholder services.

I have random php array like this:

$images = array(
    'http://loremflickr.com/400/200/',
    'http://placehold.it/300/100/',
    'http://lorempixel.com/600/600/',
    'http://loremflickr.com/300/300/',
    'http://placehold.it/300/100/',
    'http://loremflickr.com/500/400/',
    'http://lorempixel.com/100/100/',
);
$output = $images[array_rand($images)];

The problem is: if I use this to fill 20 placeholders on one page then there are multiple image duplicates, every image is used at least twice. Shouldn't these placeholders load random images out of tens or thousands of them? Or what am I doing wrong?

Upvotes: 1

Views: 486

Answers (2)

Kamran
Kamran

Reputation: 2741

while displaying your image just add a random number at the end of img src

<img src="<?php echo $output."?".rand(); ?>" />.

This will prevent caching and hopefully you will get all random images.

Upvotes: 2

Ahmed Ziani
Ahmed Ziani

Reputation: 1226

Try with this

    $images = array(
        'http://loremflickr.com/400/200/',
        'http://placehold.it/300/100/',
        'http://lorempixel.com/600/600/',
        'http://loremflickr.com/300/300/',
        'http://placehold.it/300/100/',
        'http://loremflickr.com/500/400/',
        'http://lorempixel.com/100/100/'
    );
    $output = $images[array_rand($images)];

Without comma (,) in the end of array

Upvotes: 0

Related Questions