验证php中的url参数
我的 .htaccess 页面中有规则,显示属性 id 等...
我想确保验证我得到的每个参数以获得正确的查询。
我有:
RewriteRule ^(.*)$ page.php?page=$1
RewriteRule ^property/(.*)$ property.php?pid=$1
所以在我的 php 中我有:
$page = $_GET['page'];
现在
$propertyid = $_GET['pid'];
我需要保护它们,但我想知道哪种方法最适合用来保护这些,这就是我丢失的地方。
I have rules in my .htaccess for pages, show property id etc...
I want to make sure I validate every parameter I get to the right query im getting.
I have:
RewriteRule ^(.*)$ page.php?page=$1
RewriteRule ^property/(.*)$ property.php?pid=$1
so in my php I do:
$page = $_GET['page'];
and
$propertyid = $_GET['pid'];
Now I need to secure them but I want to know which method is best to use to secure these and that is where im lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说使用这些规则:
这样,如果有人输入除字母和数字(对于页面)和数字(对于属性)之外的任何字符,它将显示找不到页面。
如果您想确实确定,您可以
$page = mysql_real_escape_string($_GET['page']);
只需确保您的数据库连接已打开并且您可以强制转换pid 类似$propertyid = (int)$_GET['pid'];
I would say to use these rules:
this way if someone enters any characters other than letters and numbers (for pages) and numbers (for property) it will show a page not found.
If you want really to be sure, you can
$page = mysql_real_escape_string($_GET['page']);
just make sure your database connection is open and you can cast the pid like$propertyid = (int)$_GET['pid'];
我认为使用页面参数,您应该有一个接受页面的列表,然后在获取“页面”之后,检查“页面”是否在接受列表中。
例如:
和 id:
希望这有帮助:)
i think with page parameter you should have a list of acept pages, then after get 'page', you check if 'page' is in accept list.
For example :
And id :
hope this help :)