Namit
Namit

Reputation: 1322

Images loading on localhost but not using IP

I am using a PHP script to read some folders in directory and based on their names retrieve their posters. All of this works fine on localhost. However, when opening externally, this does not work and results in blank images.

A screenshot from localhost:Screenshot of localhost


The problem can be found at 89.241.171.100/Prac/. PHP generating img tag:

while (false !== ($entry = readdir($handle))) {
      $counter++;
      echo "<span class='title'>
              <img src='holder.js/200x280/text:$entry' 
                   alt='$entry' 
                   onload='loader(this, \"$entry\")' />
                   </span>";
      if($counter == 5) break;
 }

PHP fetching the src for the images called via ajax from loader():

if($_POST['title']) {
    $title = $_POST['title'];
    $imdb = new Imdb();
    $movieArray = $imdb->getMovieInfo("$title");
    $link = $movieArray["poster_large"];
    echo $link;
}

Loader() function:

$.ajax({
     type: 'post',
     url: 'loader.php',
     data: 'title='+title,
     success: function(data) {
          img.src = data;
     }
 });

Upvotes: 0

Views: 868

Answers (2)

calcinai
calcinai

Reputation: 2617

This looks like an issue with the way you're loading it. These images are being provided via Akamai's CDN and it's not liking the referrer that it's getting.

Here's what's being returned instead of the image payload.

<HTML><HEAD>
<TITLE>Referral Denied</TITLE>
</HEAD><BODY>
<H1>Referral Denied</H1>
You don't have permission to access "http&#58;&#47;&#47;ia&#46;media&#45;imdb&#46;com&#47;images&#47;M&#47;MV5BMTM5NjM0ODY1NF5BMl5BanBnXkFtZTcwMjk5NjI0Ng&#64;&#64;&#46;&#95;V1&#46;&#95;SY500&#46;jpg" on this server.<P>
Reference&#32;&#35;24&#46;24c633b8&#46;1366714063&#46;2a353f15
</BODY></HTML>

I'm not encouraging breaching anyone's terms but this might be of some use to you, I suspect that passing an empty referrer will fix the problem as when you visit the image URL directly it works (and doesn't send a referrer).

EDIT:

This fiddle is a working example of what I was suggesting earlier. You'll notice the image directly linked is dead, but the one with no referrer loads perfectly.

Upvotes: 1

DarkBee
DarkBee

Reputation: 15605

U could use the Imdb API

Just request the data with : http://imdbapi.org/?id={id}&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple

{id} being the imdb id of the movie. Then u can access the picture with :

$data = json_decode(file_get_contents("http://imdbapi.org/?id={id}&type=json&plot=simple&episode=1&lang=en-US&aka=simple&release=simple"));
$img = $data->poster;

Upvotes: 1

Related Questions