Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    188
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Prevent Url Variables that arent in use

    Hi

    Does anyone know how to prevent people from putting unused variables in a page. For example if you go to http://google.com/?a=a it gives a 404 error. I'd like to do the same or do a 301 redirect.

    thanks

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Here's a bit of PHP I use. It redirects ALL query strings to the equivalent URL without the query string though, so if you want to allow some, you'll need to tinker with it. Perhaps by having an array of "safe" values that can be used. Should be a good start point though.

    PHP Code:
    $requested $_SERVER['REQUEST_URI'];
    if (
    strpos($requested'?') > 0){
      
    $uri_array explode('?'$requested);
      
    $redirect 'http://www.yourdomain.com'.$uri_array[0];
      
    header("HTTP/1.0 301 Moved Permanently");
      
    header("Location: $redirect");



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •