Find the Current URL with PHP

Find the Current URL with PHP

Find the Current URL with PHP
=======================

URL to a current page contains in three parts:

1. Domain name
2. Path to the page
3. Query string

This information are stored in the $_SERVER array. we can get from this array.

Code:

<?php
$domain_name = $_SERVER[’HTTP_HOST’];
$path = $_SERVER[’SCRIPT_NAME’];
$query_string = $_SERVER[’QUERY_STRING’];
$url = “http://” . $domain_name . $path . “?” . $query_string;
echo “URL: ” . $url . “<br />”;
?>

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.