验证php中的url参数

发布于 2024-12-27 04:00:23 字数 376 浏览 4 评论 0原文

我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对你而言 2025-01-03 04:00:23

我想说使用这些规则:

RewriteRule ^([a-z0-9]+)/?$ page.php?page=$1 [L,NC]
RewriteRule ^property/([0-9]+)/?$ property.php?pid=$1 [L,NC]

这样,如果有人输入除字母和数字(对于页面)和数字(对于属性)之外的任何字符,它将显示找不到页面。

如果您想确实确定,您可以

$page = mysql_real_escape_string($_GET['page']);只需确保您的数据库连接已打开并且您可以强制转换pid 类似 $propertyid = (int)$_GET['pid'];

I would say to use these rules:

RewriteRule ^([a-z0-9]+)/?$ page.php?page=$1 [L,NC]
RewriteRule ^property/([0-9]+)/?$ property.php?pid=$1 [L,NC]

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'];

℡寂寞咖啡 2025-01-03 04:00:23

我认为使用页面参数,您应该有一个接受页面的列表,然后在获取“页面”之后,检查“页面”是否在接受列表中。
例如:

$arr_pages = ('page1','page2','page3');
$page = $_GET['page'];
if(in_array($page,$arr_pages))
{
// do some thing
}
else
{
 // page not found
}

和 id:

$propertyid = intval($_GET['pid']);

希望这有帮助:)

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 :

$arr_pages = ('page1','page2','page3');
$page = $_GET['page'];
if(in_array($page,$arr_pages))
{
// do some thing
}
else
{
 // page not found
}

And id :

$propertyid = intval($_GET['pid']);

hope this help :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文