dongzhan1878 2016-06-15 01:56
浏览 27
已采纳

自动获取显示我的图片的网站的网址?

I've been trying to get the URL (including GET parameters) of a site that is displaying my image. This is because I want to extract one parameter of the URL.

A friend told me that she knew someone that could achieve this, but I don't know if he was doing it with an image. Also I don't think I can do it with a link because when going to external sites it will appear a warning page saying that you're being redirected outside, so if I put a link to my page and someone clicks, I will get the referrer URL of redirection warning page. I can't assure if my friend was telling the truth about this, but it's very likely that it was true.

All I could get with the image was the IP and other things of the HTTP header, but the referrer part is empty and I thought that the referrer contained the full URL I'm talking about.

This is what I have tried. First the img tag in the other site in BBCode:

[img]http://______.com/get_image.php?i=myimage[/img]

And in my site this script in PHP, although any language that does the work would be good for me:

<?php
// Get name of image to be displayed (non-sanitized here for simplicity)
$filename = $_GET["i"];

// Here I want to get the site where image is being viewed
if (!empty($_SERVER['HTTP_REFERER'])) {
        $visitor_url = $_SERVER['HTTP_REFERER'];
} else {
        $visitor_url = "none";
}

// And write the referrer to a file just to test if it works
$fp = fopen('referer.txt', 'w');
fwrite($fp, $visitor_url);
fclose($fp);

// Eventually display the image
header('Content-Type: image/png');
readfile($filename . '.png');
?>

So my questions are:

  1. Is it possible to get full URL of a site that is displaying my image?
  2. If not, is there any other method to get the full URL?

Thank you in advance.

Note: I don't have any permision in the other site where I'm posting the image, I'm just an user there. Please tell me if I'm missing something or I have to ask this in another way, I'm new to StackOverflow.

  • 写回答

4条回答 默认 最新

  • dttvb115151 2016-06-16 15:34
    关注

    I fixed this problem by switching my site (where image is hosted) to HTTPS. The code in my question was doing its job correctly.

    It looks that HTTP_REFERER was blank because of it coming from an HTTPS site and my site being HTTP it would always send it blank. I was aware that it could be a problem, but didn't make much sense for me because HTTP_REFERER was also blank when coming from another HTTP site (which I think it's not normal) so I thought the error was in another place.

    Usually HTTP_REFERER is sent when it comes from and goes to:

    1. from HTTP to HTTP
    2. from HTTPS to HTTPS
    3. from HTTP to HTTPS

    But it's not sent when it comes from and goes to:

    1. from HTTPS to HTTP

    And in my case, I don't know why, it wasn't being sent from HTTP to HTTP which was confusing me.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?