繁体   English   中英

如何将 SOMETHING.php 转换为 INDEX.php?site=SOMETHING

[英]How to convert SOMETHING.php to INDEX.php?site=SOMETHING

我有一个 php 网站。 我有一个问题。 我有一些文件,比如 rules.php contact.php

该网站看起来像 site.com/rules.php 等如何制作类似的东西:site.com/index.php?=rules

我不知道我是否正确地编写了第二个版本。

实现此目的的一个简单方法是使用包含使用$_REQUEST通过查询字符串获得的值

在 index.php 你会有

<h1>your called page</h1>
<?php 
    if($_REQUEST['file'] != "")
    {
        include $_REQUEST['file'].".php";
    }
?>
<p>end of index.php</p>

在您的 rules.php 页面中,您将拥有

<p>obey the S.Ex G'ods</p>

然后你用以下命令调用 index.php

site.com/index.php?file=rules

你会看到 rules.php 上的任何内容都将显示在 index.php 中<h1><p>

Stack Exchange 全球模组

然后,您可以对此进行扩展,这样您就不必提供文件路径或指定在数据库中查找的代码1


1:不要忘记消毒

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM