• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

How to get the full URL?

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
narmi2
Asked:
narmi2
1 Solution
 
hieloCommented:
Try:

echo $_SERVER['PHP_SELF'] . ( !empty($_SERVER['QUERY_STRING']) ? "?" . $_SERVER['QUERY_STRING'] : "";
0
 
Loganathan NatarajanLAMP DeveloperCommented:
you can also try,


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

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperCommented:
also,
$url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
narmi2Author Commented:
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
 
bevhostCommented:
You may also want
        if ( isset($HTTPS) && $HTTPS == 'on' ) {
          $PROTOCOL='https';
        } else {
          $PROTOCOL='http';
        }
        echo $PROTOCOL. "://".$_SERVER["HTTP_HOST"];
0
 
Loganathan NatarajanLAMP DeveloperCommented:
dear narmi2

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

Open in new window

0
 
narmi2Author Commented:
REQUEST_URI did the trick.  Thanks
0
 
Loganathan NatarajanLAMP DeveloperCommented:
Coool!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now