Solved

How to get the full URL?

Posted on 2008-06-18
9
260 Views
Last Modified: 2010-05-19
Dear Experts,

How do you get the current url and echo it onto the screen?

I have tried $_SERVER['PHP_SELF'] but it gives me back the actual url instead of the url written in the address bar.

Please help.
0
Comment
Question by:narmi2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 21811783
Try:

echo $_SERVER['PHP_SELF'] . ( !empty($_SERVER['QUERY_STRING']) ? "?" . $_SERVER['QUERY_STRING'] : "";
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 21811805
you can also try,


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

Open in new window

0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21811807
also,
$url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21811813
0
 
LVL 1

Author Comment

by:narmi2
ID: 21811816
What I mean is, php_self returns something like /folder/filename.php

I am using .htaccess to rewrite the url to something like

/folder/filename-p3.php

How do I get the rewritten url, i.e. the url which is displayed in the address bar?
0
 
LVL 19

Expert Comment

by:bevhost
ID: 21811822
You may also want
        if ( isset($HTTPS) && $HTTPS == 'on' ) {
          $PROTOCOL='https';
        } else {
          $PROTOCOL='http';
        }
        echo $PROTOCOL. "://".$_SERVER["HTTP_HOST"];
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21811835
dear narmi2

did you try this?
<?php
$url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
echo $url;
?>

Open in new window

0
 
LVL 1

Author Comment

by:narmi2
ID: 21811840
REQUEST_URI did the trick.  Thanks
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21811848
Coool!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question