如何知道我在哪个php页面?

时间:2015-09-21 09:37:18

标签: php .htaccess url-rewriting

我目前交给了一个由不同公司托管的php项目。我的核心域是Java所以与PHP相关的一切对我来说都是新的。当我运行项目时很难知道浏览器是哪个PHP文件显示,因为URL没有显示由于'URL重写'的实际PHP文件名。我试图删除URL重写规则表单.htaccess文件,但然后应用程序停止工作,因为我做了圆顶错误。为了得到项目的流程我只是需要知道浏览器当前显示的文件。请帮我实现这一目标。

5 个答案:

答案 0 :(得分:1)

echo __FILE__;    
$included = get_included_files();
var_dump($included);

答案 1 :(得分:1)

使用:

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

或使用可以使用print_r($_SERVER)您想要了解的文件和服务器

答案 2 :(得分:0)

您可以使用basename()和$ _SERVER ['PHP_SELF']获取当前页面文件名

echo basename($_SERVER['PHP_SELF']); /* It's returns The Current PHP File Name */

答案 3 :(得分:0)

.htaccess文件中有多少次重写? 他们每个人都应该引导您到一个特定的文件,这是您正在寻找的文件。

答案 4 :(得分:0)

PHP具有Magic Constants,其中包含其文件所需的信息:http://php.net/manual/en/language.constants.predefined.php

__LINE__       The current line number of the file.
__FILE__       The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.
__DIR__        The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory.
__FUNCTION__   The function name.
__CLASS__      The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.
__TRAIT__      The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar).
__METHOD__     The class method name.
__NAMESPACE__  The name of the current namespace.

就这样使用它:

echo __DIR__;