Dynamic PHP images requesting url - php

I have a PHP script that generates dynamic images using GD. The image may be accessed remotely via, for example, http://mysite.com/scripts/phpimages.php
Any remote website such as example.com could able to render this image in its client side HTML img tag. For example:
<!-- http://example.com/about.html -->
<img src="http://mysite.com/scripts/phpimages.php" />
What I need that my script able to know the URL of the image requested page i.e http://example.com/about.html

Use this
echo $_SERVER['HTTP_REFERER'];
To prevent errors,
if(isset($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'];
}

Related

Treat page URL as image URL

I want to use page url eg. example.com/randomimage/ in HTML <img> tag to display random images.
Is that possible with PHP?
I can change /randomimage/ page code via page-randomimage.php file.
You can't return an HTML page from your PHP script for that to work. In HTML, <img> tags are designed to load image content, not HTML content.
Instead you could program page-randomimpage.php to redirect to a random image URL. Something like this random redirect script but with image URLs in it rather than website URLs. The redirects should be "302 Temporary" type redirects so that the redirector result is not cached by browsers.

Instagram feed image not displaying

I am successfully pulling in the url for each image for a particular tag via PHP, but the image simply will not display. I saved the image(s) off locally and it displayed just fine, but not when referencing the url in the src attribute.
<img src="http://origincache-prn.fbcdn.net/1597216_736275239737299_176271816_a.jpg" />
You can follow the above source link to the image, and this is how the img tag is set in html, but it will not display in the browser.
Any suggestions?
Thanks in advance.
I'm not sure but can this have something to do with REFERER-check?
I mean - my chrome doesn't shows up WHY the request get's blocked, when I embed it to a website.
You should figure it out (my linux-curl shows the pic with referer set, but i'm not sure if this works!).
An idea would be to provide a php-file which is just a WRAPPER for sending to image:
<?php // redirect.php
header('Location: ' . $_GET('r'));
die();
usage:
<img src="redirect.php?r=<?php echo urlencode('http://origincache-prn.fbcdn.net/1597216_736275239737299_176271816_a.jpg"');" />
Because modern browsern do not send "REFERER" when redirected through status-header 302 Redirect
just have a try...
This is possibly related--Facebook share dialogs that attempt to share images from the FB CDN origincache end up with a 500 Internal Server Error and a blank page. I know that FB throws an error when sharing other images on FB, but you usually get a descriptive error message and not just a server error.

How to return an image from own PHP page using other server url

How can I make a PHP page that will return image from other server specified by url in variable, like this:
http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png
And after going to that page an image should apear.
It need to work for any other srcs too.
(Why like this?
I want to try bypass the Security Error that apears using toDataUrl from canvas while using image not from the same domain, by using http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png as a image src used in canvas)
You can try with
echo file_get_contents($_GET['src']);
In MyScript.php, use $_GET['src'] as the source of the image
<img src="<? echo $_GET['src']; ?>" />

have img src = dl-main.php?f=filename.jpg retrieve said image from remote server

I am trying to do the following; dynamically pick a server with the image on it, and then show said image in img src="". Yeah I know, I am horrible at explaining stuff like this but this should clear it up:
dl-main.php (on server0.domain.com)
$url = 'http://server2.domain.com/offerimage.php?f='.$_GET["f"];
header( 'Location: '.$url ) ;
offerimage.php (on server2.domain.com)
//Lots of link-protection stuff here
$f = "/".$_GET["f"];
$url = 'http://server2.domain.com'.$uri_prefix.$m.'/'.$t_hex.$f;
echo' <img src="'.$url.'"></img> ';
dl.php (on many other servers)
img src="http://server0.domain.com/dl-main.php?f=lalala.gif"
So it pretty much goes like this: Random person adds img src directing to dl-main.php?f=filename on server0. server0 then decides which server will provide the image. In the above example I am using only one server; server2
Now I simply want dl.php to show the photo hosted on server2.domain.com .
As it stands when I directly visit dl-main.php it succesfully redirects me to dl.php, which then succesfully shows me the image I requested. But when I use dl-main.php in a img src it doesn't show the image. I didn't expect it to work but it was worth a shot, but now I don't know what to do anymore :o
I hope this failed attempt is a good example of what I'm trying to accomplish here.
Thanks!
Here's the problem. You call image from server0 using:
<img src="http://server0.whatever/dl-main.php?f=thatimage.something" />
Where the dl-main.php code redirects to server2. Here, you do:
echo' <img src="'.$url.'"></img> ';
So basically the original img tag would get another img tag instead of the image data. That's why the browser can't render the image. You should echo the content of the image instead of an img tag.
Try using your browser's developer tools and check the request to server2 to verify my guess.
It can't work, your second script (offerimage) is producing text/plain, you should produce image/...in order to use img

Loading external website with PHP file

I'm using JQuery to resize an iframe to make it have the same height as it's content, it works perfectly though it only works if the content is in the same domain.
I need to display external content so I'm making the iframe point to a file in my server which in turn should display the external content:
<iframe src="frame.php" scrolling="no" frameborder="0" noresize="noresize" style="width:100%; border: 1px solid black;">
How do I make frame.php display the content of the external domain?
In case you need more info here is the answer on how to do it (he explains everything excepts how to display content in the php file):
AutoHeight IFrame
Thanks
So you want to fetch the contents of an external site?
This will work, but it'll break the layout when the target page has non-absolute URLs and relative links:
frame.php:
<?php
echo file_get_contents($_GET['url']);
?>
<?php echo file_get_contents( "http://example.com" );?>
Somethhing like that will do
Unfortunately, php isn't the correct language to be doing this. In order to determine the height of the document in the iframe, you would need to make a javascript call from the parent document (where the iframe element is) to the document referenced in the src of the iframe.
In the case where the src of the iframe is on your domain, you have full permission to use the DOM of the document to get the document's height, as per the same origin policy. When you load a document from another domain, you do not have permission to query for the height. What the answerer of your question seems to be suggesting is setting up a proxy on your site so that the same origin policy would be circumvented.
However, there going to be other issues with that (ie relative links on the proxied page, etc.)

Categories