?
Solved

How to get the full URL?

Posted on 2008-06-18
9
Medium Priority
?
271 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 2000 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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

762 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