PHP GET URL local domain


PHP GET URL local domain

我有一个名为get.php的重定向页面,其中包含以下代码:

  header('Location: '.urldecode($_GET['url']));
  $url = (isset($_GET[url]) && !empty($_GET[url])) ? $_GET[url] : NULL;
  if(empty($url)){
  header('Location: http://www.example.com/404');
}

用于reftracking的链接。当我检查日志时,我发现有人滥用它指向非恶意软件网站ie。

http://www.example.com/get.php?s&url=http://i-am-malware.yes

如何防止这种滥用,只接受在本地域

试试这个

$url = "";
if(isset($_GET['url']))
{
    $url = urldecode($_GET['url']);
}
if($url=="")
{
    header('Location: http://www.example.com/404');
    exit;
}
else
{
    $arr = parse_url($url);
    if($arr['host']==$_SERVER['SERVER_NAME'])
    {
        header("Location:".$url);
    }
    else
    {
        header('Location: http://www.example.com/404');
    }
    exit;   
}