doumaque6551 2015-10-15 06:35
浏览 36
已采纳

使用php获取请求域

I have problem with getting domain name using HTTP_REFERER. The condition is like this:

http://www.example.com send a curl post to my server. The things is, example.com does not send their url in curl_setopt(CURLOPT_REFERER). So is it possible on my server side to get their domain name ?

Thanks a lot for helping me

My code so far:


on abc.com side

$data = array('username' => $username ,
              'email' => $email,
              'phone' => $phone );

    $string = http_build_query($data);
    // For debugging purpose
    // echo $string;

    $ch =  curl_init("http://localhost/test/str_pos.php");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
    curl_close($ch);

    header("Location: str_pos.php");

On my server side:

$domain = parse_url($_SERVER['HTTP_REFERER']);

    if (isset($domain['host'])) {

        echo $domain['host'];
    }
    else{
        echo "No host found";
    }
  • 写回答

1条回答 默认 最新

  • drgd73844 2015-10-15 07:01
    关注

    I would advise a different command. Instead of HTTP_REFERER try HTTP_HOST or SERVER_NAME.

    Example:

    $domain = parse_url($_SERVER['HTTP_HOST']);

    $domain = parse_url($_SERVER['SERVER_NAME']);


    HTTP_REFERER - The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

    Source http://php.net/manual/en/reserved.variables.server.php

    Check out the following threads here and here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路