使用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");
Run Code Online (Sandbox Code Playgroud)
在我的服务器端:
$domain = parse_url($_SERVER['HTTP_REFERER']);
if (isset($domain['host'])) {
echo $domain['host'];
}
else{
echo "No host found";
}
Run Code Online (Sandbox Code Playgroud)