2016-06-17 62 views
-2

我有这个站点如何防止url参数?

site.com/path/file.php 

我想阻止用户添加file.php?id=file.php

后的任何事情我应该怎么办?我想这样做的网址,因为它是,并防止任何额外的参数

我想要做的事情是解析的网址,但这将有助于玩参数?

我的意思是如果解析器读取file.php?id和请求的网页file.php?page=

+5

你不能阻止它,但你可以忽视它或重定向无效请求。 –

+1

如果你不使用GET参数,somone添加它们并不重要。我相信很少有人会尝试只是随机添加params到一个网址。 – JimL

+0

你可以在'.htaccess'中做一个重定向。 – chris85

回答

1

你能赶上任何参数,在URL或张贴,有:

if (count($_GET)+count($_POST) > 0) 
{ 
    <execute some error code> 
    die('Ah, you cannot do that!'); 
} 
+0

这是帮助太谢谢 –

0

一种方法,你可以尝试不使用相同的页面处理功能。使用AJAX请求并限制您指定的Post PHP页面,如“/include/processmyform.php”或其他内容,以允许AJAX请求/仅允许来自Web服务器的AJAX请求。

define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); 
if(!IS_AJAX) { 
    #You can use this condition to ignore or block their request. 
    die('That method is not allowed!'); 
} else { 
    #If they did post AJAX, make sure it's a legitimate request from your server. 
    $pos = strpos($_SERVER['HTTP_REFERER'],getenv('HTTP_HOST')); 
    if($pos===false) { 
     die('That method is not allowed!'); 
    } else { 
     #All good - Cooking with hot grease! 
     $id = htmlspecialchars($_POST['id']); 
     $somevar = htmlspecialchars($_POST['someparam']); 
    } 
}