Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果页面直接链接到javascript或php,是否重定向?_Php_Javascript - Fatal编程技术网

如果页面直接链接到javascript或php,是否重定向?

如果页面直接链接到javascript或php,是否重定向?,php,javascript,Php,Javascript,我需要一些javascript或php代码来检测用户是否直接链接到我网站的页面,这样我就可以将其重定向到主页 这可能吗?如果推荐人为空,这将重定向到主页: <?php if(!empty($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'], 'example.com') header("Location: example.com"); ?> 检查服务器的主机是否在中(它是用户访问的最后一个ur

我需要一些javascript或php代码来检测用户是否直接链接到我网站的页面,这样我就可以将其重定向到主页


这可能吗?

如果推荐人为空,这将重定向到主页:

<?php
if(!empty($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'], 'example.com') header("Location: example.com"); 
?>

检查服务器的主机是否在中(它是用户访问的最后一个url)


不直接链接的替代方案是什么?i、 你什么时候不想重定向?你说的“直接链接”是什么意思?这就像在别人的页面上发布你页面的链接吗?你的意思是如果推荐人是空的?
<?php
  $referrer = $_SERVER['HTTP_REFERER'];

  // see if they are visiting from another website
  if (!empty($referrer) && stripos($referrer, 'mydomain.com') === false)
  {
    // redirect them to the main site
    header('Location: http://mydomain.com/');
    // stop php from going further
    exit;
  }
function is_direct_link() {
    return (!empty($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false);
}

if (is_direct_link()) {
    header('location: http://www.google.com');
    exit();
}