Solved

How to get the full URL?

Posted on 2008-06-18
9
255 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
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 21811813
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

932 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

10 Experts available now in Live!

Get 1:1 Help Now