我在使用 HTTP_REFERER.
获取域名时遇到问题
条件是这样的:
http://www.example.com 向我的服务器发送 curl 帖子。事情是,example.com 不会在 curl_setopt(CURLOPT_REFERER)
中发送他们的网址。那么我的服务器端有可能获得他们的域名吗?
非常感谢你帮助我
到目前为止我的代码:
在 abc.com 方面
$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");
在我的服务器端:
$domain = parse_url($_SERVER['HTTP_REFERER']);
if (isset($domain['host'])) {
echo $domain['host'];
}
else{
echo "No host found";
}
最佳答案
我会建议一个不同的命令。而不是 HTTP_REFERER
尝试 HTTP_HOST
或 SERVER_NAME
。
例子:$domain = parse_url($_SERVER['HTTP_HOST']);
$domain = parse_url($_SERVER['SERVER_NAME']);
查看以下线程 here 和 here 。
关于php - 使用php获取请求域,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33141474/