Solved

How to get the full URL?

Posted on 2008-06-18
9
257 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 dynamically set the form action using jQuery.

773 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