如何重定向输入错误的url


how to redirect wrong entered url

我当前的url是http://domain.com/example.php/link=eg但如果有人玩url并将url设置为http://domain.com/example.php/abcdefgh97654-任何事情,我的所有功能,该页面上的所有链接都将变为非活动状态。

我尝试在php文件中的所有链接之前使用<?=HTTP_SERVER;?>,但由于我的网站有用户注册和登录,当用户登录并点击任何菜单时(php脚本中的链接)。它在index.php页面上抛出。但如果用户再次登录,它会完美工作。简而言之,用户需要登录两次才能使一切完美。

  1. 基本上我想要两个解决方案一个我想要重定向www点domain dot com/example dot php/abcdefgh97654-任何东西(错误的urlpage)到errorpage(我已经在htaccess中这样做了),但没有适用于上述类型
  2. 列出项目

并且要解决两次登录的问题。

如果有人对此有解决方案,我们将不胜感激。

要做到这一点,您必须知道应该通过$_GET变量将哪些值传递到页面。然后可以为值和用户header();函数创建过滤器。这是我的建议:

<?php
$var=$_GET['val']
//get expected length if you need.
if(strlen($var)>9 or strlen($var)) {
$redirect=true;
}
//if you know what you are expecting
$vals=array('val1', 'val2, 'val3');
if(!in_array($var, $vals)){
$redirect=true;
}
//continue or replace your filters in this manner and asign your value to $redirect
if($redirect==true) {
header("Location:url"); // do this before anything else is printed to the page or else it will say headers already sent.
}
?>