Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Free host forum is not reliable
- Using Cron Job to process PHP scripts
- job interview questions (1)
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- PHP connect IBM db2 database in XAMPP
- Set up a child account and set screen time limit in Windows 8
- Datatable export excel wraptext and newline
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHPMailer 5.2.4 and use smtp gmail
Wednesday, March 27, 2013
PHP, get relevant URL of the current page
In PHP project development, we often need to get some of the relevant URL of the current page, below is some tip:
test URL:
http://localhost/jiansenlu/index.php?userid=2
/ / Get the domain name or host address localhost
echo $ _SERVER ['HTTP_HOST']. "<br>";
/ / Get the web address /jiansenlu/index.php
echo $ _SERVER ['PHP_SELF']. "<br>";
/ / Get URL parameters userid=2
echo $ _SERVER ["QUERY_STRING"]. "<br>";
/ / Get user agent
echo $ _SERVER ['HTTP_REFERER']. "<br>";
Get the full url
http://localhost/jiansenlu/index.php?userid=2
echo 'http://'. $ _SERVER ['HTTP_HOST']. $ _SERVER ['REQUEST_URI'];
or
echo 'http://'. $ _SERVER ['HTTP_HOST']. $ _SERVER ['PHP_SELF']. '?'. $ _SERVER ['QUERY_STRING'];
/ / contains the port number of the complete url
http://localhost:80/jiansenlu/index.php?userid=2
echo 'http://'. $ _SERVER ['SERVER_NAME']. ':'. $ _SERVER ["SERVER_PORT"]. $ _SERVER ["REQUEST_URI"];
/ / only take the path http://localhost/jiansenlu
$ url = 'http://'. $ _SERVER ['SERVER_NAME']. $ _SERVER ["REQUEST_URI"];
echo dirname ($ url);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment