如何改变目录时,我点击链接在PHP


How to change to directory when I click on link in PHP?

当点击index.php上的链接时,我想从input/index.php运行hello.phpinput/output/hello.php。我在谷歌上搜索过,但找不到解决方案?有解决办法吗?

在URL里放一个/

<a href="output/hello.php">

有时,我有一个问题,当只是使用(与您的例子)"output/hello.php"所以我用"。/output/hello.php",也许它可以为你工作。

我认为你问的更多是关于url,你必须创建一个名为

的文件
.htaccess

就像那样,在开头加一个点。你可以在里面使用下面的代码:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php?u=$1

现在,所有的请求都将转到index.php文件,全部!!不管你写/拉拉拉拉,还是会到index。php,所以你需要解析URL,这样你就能知道你接收到什么并能执行任何你想要的方法。例子:

$url = 'http://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];
$parsedUrl = parse_url($url);
$parsedUrl['path'] // Is the var that has the info after yourdomain.com/

一旦你有了它,你就可以用explode('/', $parsedUrl['path'])分离它并分析数据。写入/input/output/hello。php可以在index。php

中接收数据