Get full web page URL from address bar

In this tutorial, you'll learn how to get current web page url from your web browser address bar using php script.


echo $url;


In this tutorial, you'll learn 2 functions in php to get full url from address bar.


$_SERVER['HTTP_HOST'] - This function will show only server name.
$_SERVER['REQUEST_URI'] - This function will show you the path to file of your url.



In the image is a url from apple website. When you run $_SERVER['HTTP_HOST']; you'll get result "" only, no "http://" no "/downloads/dashboard/email_messaging/todo.html"

echo $server;

You'll get this is result

When you run the script "$_SERVER['REQUEST_URI']" you'll get the result below.
no "http://" and no "


echo $request_url;

This is a result when you run $_SERVER['REQUEST_URI']

To get full URL from this site you, we have to use (.) to connect 2 functions together and create http:// by yourself.

echo $url;

Display URL in text box (included javascript, click to select all text in text box)

youtube url This is an example of javascript and php script, click to select all text in text box like or many other site.

############### Code

<title>Get url for address bar</title>

<script type="text/javascript">
function select_all()
var text_val=eval("document.form_name.type");


<form name=form_name method=post action=''''>
<input name="type" type="text" id="type" value="
<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>" size="50" onClick="select_all();">


Similar Post

PHP Script Image of the day

In this script shows you how to display image of the day. You can adapt this script to display quote of the day, knowledge of the day or something else you want. You don't have to change image everyday just change images once a week.

PHP Limit upload file size

This upload form can limit file size.