views:

307

answers:

5

I have a strange situation with PHP working differently from HTML. I'm not a web programmer, just messing around. In HTML my images appear fine, in PHP the images are broken. And only public images from my Dropbox https server are broken, ones from a http server work.

As an example, here are two files on my localhost, abc.html and def.php. They try to display two images, one pointing to my https image, and another pointing to the Google logo.

abc.html:

<img src='https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM'&gt;
<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'&gt;

def.php:

<?php
echo "<img src='https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM'&gt;";
echo "<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'&gt;";
exit;

Browsing to abc.html shows both images perfectly. Browsing to def.php only shows the Google logo and the other image is broken.

It doesn't work on Firefox however someone told me it works on Opera.

Ideas please :)


Edit: def.php outputs this:

<img src='https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM'&gt;&lt;img src='http://www.google.co.uk/intl/en_uk/images/logo.gif'&gt;
A: 

This works on my Firefox version 3.6, the image shows perfectly well:

<HTML>
<HEAD>
<TITLE>My WebPage</TITLE>
</HEAD>
<BODY>

  <img src="https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM" />

</BODY>
</HTML>
Sarfraz
Is that the source of a PHP generated page? I can get it to work from a normal HTML page just not from a PHP generated one.
demoncodemonkey
+1  A: 

I'd recommend installing FireBug to see what the return response from the server is. You might find that DropBox is refusing to serve requests for images with referrals from files ending with certain extensions, e.g. .php.

This might explain the duplicate behaviour with the plain HTTP too.

David Grant
I installed Firebug, and the command line output for the page gave this error: "NetworkError: 404 NOT FOUND - https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM". I don't know how to decipher the response headers to figure it out.
demoncodemonkey
Perhaps you could supply the headers?
David Grant
According to the creator of a Dropbox gallery plugin, "Dropbox don't allow to show photo with HTTP_REFERER different of dropbox.com". This sort of confirms your theory, so you get the points.
demoncodemonkey
A: 

Try this:

<?php
echo '<img src="https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM"&gt;';
echo '<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif"&gt;';
exit;

If that works, it's because html attributes should be bounded by double quotes, not single quotes. Perhaps some browsers forgive that and some do not.

Scott Saunders
If browsers are unforgiving of this error, why does the Google logo work?
David Grant
A: 

An obvious observation but does your def.php have the closing php tag? Your code example does not...

<?php
echo '<img src="https://photos-1.dropbox.com/i/l/EyvpAUN99vGCmWKqw-ywSYXY1L8dPhkloKA5i9I--NM"&gt;';
echo '<img src="http://www.google.co.uk/intl/en_uk/images/logo.gif"&gt;';
exit;
?>

Edit: Saved the above as a html file, and I only see one image in Chrome... ALSO - Do you have the PHP module installed/associated with your web server?

ian_scho
The output is still valid, however.
David Grant
The PHP has been interpreted - see the output.
David Grant
You don't need the closing tag in PHP. In fact, if you submit something to PEAR, your contribution will be rejected if you include the closing tag, as it's against the PEAR coding standards: http://pear.php.net/manual/en/standards.php
R. Bemrose
@R. Bemrose. Didn´t know that you don't need the closing php tag! Thanks.@David Grant. You're right.
ian_scho
A: 

Try 'view source' in both and compare the results.

symcbean