php: get current url

by prettyscripts on 2007-12-17 01:15:42

php

PHP:

"http" . ($_SERVER['HTTPS']) ? "s" "") . "://" 
$_SERVER['SERVER_NAME'] . 
((in_array($_SERVER['SERVER_PORT'], array(80443)) ? "" ":" $_SERVER['SERVER_PORT']) . 
"/"

$_SERVER[’HTTPS’] will be non-empty value if it’s running over ssl or using https protocol.

$_SERVER[’SERVER_PORT’] 80 is standard port and 443 is standard ssl port. the port number will be appended to the url if not using these 2 standard ports.

Tags: php, url

No feedback yet

Leave a comment


Your email address will not be revealed on this site.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)