kmunky
kmunky

Reputation: 15613

How can I get the full URL in PHP?

How can I get the full URL, like http://www.domain.com/page.php?id=someid&page=1, not just http://www.domain.com/page.php?

Upvotes: 0

Views: 280

Answers (3)

Amber
Amber

Reputation: 527338

$_SERVER['QUERY_STRING'] has the query string portion of the URL.

Upvotes: 4

Zied
Zied

Reputation: 1716

A quick answer:

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Upvotes: 3

Xinus
Xinus

Reputation: 30563

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING'];

Upvotes: 1

Related Questions