[英]how to redirect wrong entered url
My current url is http://domain.com/example.php/link=eg But if someone plays with url and puts url as http://domain.com/example.php/abcdefgh97654 - anything, my all functions all links from that page become inactive. 我当前的网址是http://domain.com/example.php/link=eg,但是如果有人玩url并将url设为http://domain.com/example.php/abcdefgh97654-任何东西,我的所有功能都将全部链接从该页面变为无效。
I tried using <?=HTTP_SERVER;?>
before all links in my php files but as my website has user registration and sign in, when user signs in and clicks on any menu (link from php script). 我尝试在PHP文件中的所有链接之前使用
<?=HTTP_SERVER;?>
,但是当用户登录并单击任何菜单(来自PHP脚本的链接)时,由于我的网站具有用户注册和登录权限,因此我尝试使用<?=HTTP_SERVER;?>
。 It throws on index.php page. 它抛出index.php页面。 But if user logs in again it works perfectly.
但是,如果用户再次登录,则可以正常运行。 In short user needs to log in twice to work everything perfect.
简而言之,用户需要登录两次才能完美完成所有工作。
And want to solve two time log in problem. 并且要解决两次登录问题。
If anyone has solution for this will be appreciated. 如果有人对此有解决方案,将不胜感激。
For you to do this, you have to know what values are supposed to be passed via $_GET
variable to your page. 为此,您必须知道应该通过
$_GET
变量将哪些值传递给页面。 Then you can create filter for the values and user header();
然后,您可以为值和用户
header();
创建过滤器header();
function. 功能。 Here is my suggestion:
这是我的建议:
<?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.
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.