简体   繁体   中英

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

Use:

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

or use can use print_r($_SERVER) what ever you want to know about the file and server

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

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

How many rewrites are they in the .htaccess file ? Each one of them should lead you to a specific file, that's the one you are looking for.

PHP has Magic Constants that holds required information of its file : 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.

Just use it like this :

echo __DIR__;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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