开发者

Get username in url

I'd like to get just the username in the url, for example www.blank.com/username

The curl script I'm using returns the full url. I just want the user name here's the script.

<?php
 function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .=       $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  }
 return $pageURL;
}
?>
 <?ph开发者_开发百科p
  echo curPageURL();
?>


You can use the basename function:

$pageName = basename($_SERVER["REQUEST_URI"]);


You should find the first /-character of the url (after http://) and get the substr from there. On the page where you got the script from, there's an example on how to do it: http://www.webcheatsheet.com/PHP/get_current_page_url.php

Would be something like this:

return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜