NenTang.vn
Thiết kế Lập trình Web BackendLập trình căn bản PHP
Phân tách cấu trúc URL với PHP
Chương 5 · Bài 4
PHP Nâng cao
Thời lượng: 171 phútĐọc khoảng: 1 phút
Từ viết tắt
Nội dung bài học không khai báo từ viết tắt bằng thẻ abbr.
Nội dung bài học
Ví dụ:
Source: https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
https://(www.)example.com/subFolder/myfile.php?var=blabla#555
php
1//=================================================== //2//========== self-defined SERVER variables ========== //3//=================================================== //4$_SERVER["DOCUMENT_ROOT"] ? /home/user/public_html5$_SERVER["SERVER_ADDR"] ? 143.34.112.236$_SERVER["SERVER_PORT"] ? 80(or 443 etc..)7$_SERVER["REQUEST_SCHEME"] ? https //similar: $_SERVER["SERVER_PROTOCOL"] 8$_SERVER['HTTP_HOST'] ? example.com (or with WWW) //similar: $_SERVER["ERVER_NAME"]9$_SERVER["REQUEST_URI"] ? /subFolder/myfile.php?var=blabla10$_SERVER["QUERY_STRING"] ? var=blabla11__FILE__ ? /home/user/public_html/subFolder/myfile.php12__DIR__ ? /home/user/public_html/subFolder //same: dirname(__FILE__)13$_SERVER["REQUEST_URI"] ? /subFolder/myfile.php?var=blabla14parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)? /subFolder/myfile.php 15$_SERVER["PHP_SELF"] ? /subFolder/myfile.php16 17// ==================================================================//18//if "myfile.php" is included in "PARENTFILE.php" , and you visit "PARENTFILE.PHP?abc":19$_SERVER["SCRIPT_FILENAME"]? /home/user/public_html/parentfile.php20$_SERVER["PHP_SELF"] ? /parentfile.php21$_SERVER["REQUEST_URI"] ? /parentfile.php?var=blabla22__FILE__ ? /home/user/public_html/subFolder/myfile.php23 24// =================================================== //25// ================= handy variables ================= //26// =================================================== //27//If site uses HTTPS:28$HTTP_or_HTTPS = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS']!=='off') || $_SERVER['SERVER_PORT']==443) ? 'https://':'http://' ); //in some cases, you need to add this condition too: if ('https'==$_SERVER['HTTP_X_FORWARDED_PROTO']) ...29 30//To trim values to filename, i.e. 31basename($url) ? myfile.php32 33//excellent solution to find origin34$debug_files = debug_backtrace(); 35$caller_file = count($debug_files) ? $debug_files[count($debug_files) - 1]['file'] : __FILE__;
