簡體   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