Contoh URL: http://example.com/folder1/folder2/yourfile.php?var=blabla#12345
$_SERVER["DOCUMENT_ROOT"] === /home/user/public_html
$_SERVER["SERVER_ADDR"] === 10.34.12.123
$_SERVER['HTTP_HOST'] === example.com (atau dengan WWW)
$_SERVER["REQUEST_URI"] === /folder1/folder2/yourfile.php?var=blabla
__FILE__ === /home/user/public_html/folder1/folder2/yourfile.php
basename(__FILE__) === yourfile.php
__DIR__ === /home/user/public_html/folder1/folder2 [sama juga: dirname(__FILE__)]
$_SERVER["QUERY_STRING"] === var=blabla
$_SERVER["REQUEST_URI"] === /folder1/folder2/yourfile.php?var=blabla
parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH) === /folder1/folder2/yourfile.php
$_SERVER["PHP_SELF"] === /folder1/folder2/yourfile.php
//jika file "yourfile.php" tu include dalam "parentfile.php" , dan "parentfile.PHP?abc" dibuka:
$_SERVER["PHP_SELF"] === /parentfile.php
$_SERVER["REQUEST_URI"] === /parentfile.php?abc
$_SERVER["SCRIPT_FILENAME"]=== /home/user/public_html/parentfile.php
str_replace($_SERVER["DOCUMENT_ROOT"],'', str_replace('\\','/',__FILE__ ) ) === /folder1/folder2/yourfile.php
Jadi, nak dapatkan URL semasa secara penuh
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
Jika rasanya URL kita terlibat dengan https, sebaiknya check sekali.
$actual_link
= (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
0 comments:
Post a Comment