Getting a specific part of an url into my php script?
Posted: Wed May 23, 2007 5:40 am
I'm trying using "selfurl" and "basename" to get a certain part of the current url into my script, but cant figure it out... I want to get the part below marked with red into my script.
Can somebody please help me?!?
I have tryid with this, but I only get the last part of the url (welcome)http://www.mypage.com/index.php/en/welcome
Code: Select all
function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
: (":".$_SERVER["SERVER_PORT"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2) {
return substr($s1, 0, strpos($s1, $s2));
}
$path = (selfURL());
$page = basename($path);