0

昨天我想知道在 PHP 中使用文件名作为文件本身的参数的可能性......基本上,我有一个名为“file.php”的文件,每当通过浏览器请求任何文件时即“test1.php”,我调用文件“file.php”作为参数传递前一个文件的名称。有可能做这样的事情吗?

<Files *.php>
    //I call the "anotherpath/file.php" file passing as argument the filename of the file called before
    //i.e. Call anotherpath/file.php?arg=filename of the "virtual" file
</Files>

“test1.php”(甚至不在服务器中)调用“anotherpath/file.php”,这个可以访问“test1”字符串。提前致谢!

4

3 回答 3

1

在根目录中创建一个.htaccess文件并将此代码添加到其中。

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

现在,这会将所有请求重定向到 index.php。现在,在 index.php 中添加这段代码,

<?php
    echo $_SERVER['REQUEST_URI'] ;
?>

这会将请求的 URL 打印到 Web 浏览器中。

于 2013-07-20T08:25:41.983 回答
0

代替使用规则,另一种选择是将最后一页存储在会话中。就像是;

$lastpage = $_SESSION['LastPage'];
$_SESSION['LastPage'] = 'this page.php';
于 2013-07-20T08:12:29.710 回答
0

在 url 中发送文件名:

<a href="<?php echo $_SERVER['PHP_SELF'].'?p=page1';?>" >page1</a>
<a href="<?php echo $_SERVER['PHP_SELF'].'?p=page2';?>" >page2</a>
<div id="main-content" >
  <?php
    if(isset($_GET['p']))
      $page = $_GET['p'].".php";
    else
      $page = "default.php"
    include($page);
</div>
于 2013-07-20T08:23:49.227 回答