Solved

How to get the full URL?

Posted on 2008-06-18
9
252 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
Comment Utility
Try:

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

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
Comment Utility
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
Comment Utility
also,
$url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:narmi2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
REQUEST_URI did the trick.  Thanks
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
Coool!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now