网站如何执行此index.php?something = somepage [英] how do websites do this index.php?something=somepage

查看:139
本文介绍了网站如何执行此index.php?something = somepage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过很多基于php的网站,无论您在哪里导航,都停留在index.php上,并且在URL中传递了一些随机参数.而当我看一看开放源代码版本的人时,index.php中就有很多包含内容

i've seen alot of php based websites where no matter where you navigate your stuck at the index.php and some random parameters are passed in the url. and when i take a look at an open source version who does the same the index.php has a bunch of includes in them

我可以做同一件事的基本方法是什么?包括mod重写吗?

whats a basic way i can do the same thing? does this include mod rewrite?

谢谢

推荐答案

我已经看到了这一点,而且我个人认为这是一种糟糕的设计.特别是因为许多人不倾向于清理include参数,以便某人可以通过传递相对路径来包含他们想要的任何文件.

I've seen this and personally I think it's an awful design. Particularly because many people don't tend to sanitize the include parameter such that someone can include any file they want by just passing in a relative path.

mod_rewrite通常用于隐藏如下网址:

mod_rewrite is typically used to hide URLs like:

/index.php?path=user&include=account

用类似的东西代替它:

/user/account

像这样:

RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)/(\w+)$ /index.php?path=$1&include=$2 [L]

我通常也会输入以下内容:

I usually also put in something like this:

RewriteRule %{THE_REQUEST} \.php$ [R=404,L]

我忘记了确切的语法,但是基本上,想法是用户不能直接请求php文件.它必须通过另一个RewriteRule(与第一个类似)来完成,它可以为您清理查询字符串输入省去很多麻烦,并且避免了PHP为您原本不希望的事情创建全局变量的整个问题(尽管它们仍然可以对此进行POST) ).

I forget the exact syntax but basically th eidea is the user can't request a php file directly. It has to be done via another RewriteRule (like the first one), which can save you a lot of headaches with sanitizing query string input plus avoid the whole problem of PHP creating globals for things you never intended (although they can still POST for this).

无论如何,回到为什么我认为这是一个糟糕的主意.之所以这样做,是因为他们倾向于在每个页面中都需要一些通用代码(例如页眉和页脚).我认为实际上最好在每个页面的顶部都包含一个通用文件.这是一个更简单,更清晰的设计.

Anyway, back to why I think this is a terrible idea. They do it because they tend to want some common code in every page (like a header and footer). I would argue that you're better off actually just including a common file at the top of each of your pages. It's a simpler, clearer design.

这篇关于网站如何执行此index.php?something = somepage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆