繁体   English   中英

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

[英]How to know which php page I am on?

我目前已经移交了以前由另一家公司托管的php项目。我的核心域是Java,因此与PHP相关的所有内容对我来说都是新的。当我运行该项目时,由于浏览器自由于``URL重写'',URL并未显示实际的PHP文件名。我试图从.htaccess文件中删除URL重写规则,但随后由于圆顶错误而导致应用程序停止工作。为了获得项目流程,我只需要知道浏览器当前显示哪个文件。请帮助我实现这一目标。

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

采用:

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

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

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

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

.htaccess文件中它们重写了多少次? 他们每个人都应将您带到一个特定的文件,这就是您要查找的文件。

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__;

暂无
暂无

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

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