如何重定向错误的输入网址

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.

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). It throws on index.php page. But if user logs in again it works perfectly. In short user needs to log in twice to work everything perfect.

  1. Basically I want two solutions one I want to redirect www dot domain dot com/example dot php/abcdefgh97654 - anything (wrong url page) to errorpage (I already done this in htaccess) but does not work for above type.
  2. List item

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. Then you can create filter for the values and user 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.
}

?>