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

Form Validation Using Dreamweaver

In this tutorial shows you how to validate form using Macromedia Dreamweaver, it will show alert box when someone press submit button and forgot to fill your requied fields.

Test php mail function on your localhost

When you code php mail function you can't test it on your localhost you have to upload and test it on your hosting but now you can test php mail function on your localhost using Argosft mail server.