如何检查加载了哪个 URL 并包含基于此的页面?
<?php
if(...) {
include("home.php");
} else if(...) {
include("about.php");
}
?>
如果我单击主页按钮,它将包含 home.php 页面,如果我单击 about 按钮,它将包含页面加载的 about.php。我希望采用这种方式,这样我就可以拥有一个 index.php 文件,而不是每一页有多个文件。
有没有办法检查正在加载的网址?
<?php
if(...) {
include("home.php");
} else if(...) {
include("about.php");
}
?>
If i click on the home button it will include the home.php page and if i click on the about button it will include the about.php on page load. I want to have it this way so that i can have one index.php file and not multiple ones for each page.
Is there a way to check the url that is being loaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://php.net/manual/en/reserved.variables.server.php
http://php.net/manual/en/reserved.variables.server.php
您还可以使用 $_GET 和 switch 语句。首先检查 get var 是否已设置,如果是则使用 switch 语句,否则使用默认值。
像
这样,你就被双重覆盖了。如果未设置 get,它会自动包含 home.php,但如果设置了,则有多个预定义选项可供选择。如果有人弄乱了 url,home.php 无论如何都会被包含在内。
PHP switch 语句
You could also use a $_GET and a switch statement. first check to see if the get var is set, and if it is use the switch statement, else, use the default.
something like
This way, you are double covered. If get isn't set, it automatically includes home.php, but if it is set, you have several predefined options to choose from. if someone is messing with the url, home.php will be included anyway.
PHP switch statement
您可能还想研究 mod_rewrite。
You might also want to investigate mod_rewrite.