1

I have a page with this url (www.mysite.com/index.php?op=2&id=3#someancor). I would like to use php function parse_url for split the url but I don't know how to take the full url with ancor. I have tried so:

$base_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

$parsed_url = parse_url($base_url);
echo $parsed_url['path'];
echo $parsed_url['query'];
echo $parsed_url['fragment'];

But my base_url return www.mysite.com/index.php?op=2&id=3. How can I get the full url? Thanks

karthikr
  • 97,368
  • 26
  • 197
  • 188
Paolo Rossi
  • 2,490
  • 9
  • 43
  • 70
  • 1
    Not possible. The hash is never sent to the server. The browser uses it locally, by scrolling down to the element with that ID. – Barmar Apr 15 '13 at 14:30

4 Answers4

3

then you can use "javascript" > document.URL. and POST to some page and process there. document.URL returns the complete url with #

Abuzer Firdousi
  • 1,552
  • 1
  • 10
  • 25
0

Unfortunately this is impossible as the #... part of the url will be handled only by the browser and not being used when requesting the server.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
0

This is impossible, because everything behind the hash isn't handled by the server. Look at this answer: https://stackoverflow.com/a/967659/1341719

Community
  • 1
  • 1
Corné Guijt
  • 122
  • 1
  • 11
-1

The function will give you the current url, and you can process it.

$base_url= curPageURL();
function curPageURL() {
     $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
      $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
       $pageURL .=  $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return $pageURL;
   }
Abuzer Firdousi
  • 1,552
  • 1
  • 10
  • 25