Getting complete web page url from address bar in php

In this tutorial you will learn how to get full web page url from address bar.

<?php
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>

We are using these two php functions to get complete web page url from address bar. These two functions are
  1. $_SERVER['HTTP_HOST']
  2. $_SERVER['REQUEST_URI']
$_SERVER['HTTP_HOST'] this builtin php function will show you only server name, e.g www.yoursite.com .
$_SERVER['REQUEST_URI'] this builtin php function will show you the path to file of your url e.g www.yoursite.com/yourpage.php

So this is the way to get complete web page url from address bar in php

0 comments: