0

I don't know how to get data from the querystring in PHP.

I'd like to retrieve the data from the access_token.

http://www.mygridview.com/sephora/index.php?mod=config#access_token=170791786296375|983b6aefceafdb1cf2d5a122-100001848355029|Hc8qGl6xgpXlmhOWQrLv910on_8&expires_in=0

How do I do this in PHP?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Chirayu
  • 4,693
  • 7
  • 28
  • 46
  • The correct answer depends entirely on how you intend to make that URL available to PHP. Please clarify. [Also, this is at least a quadruplicate](http://stackoverflow.com/search?q=fragment+url+php), so you should point out which of those approaches you have tried and why it's still not working. – Gordon Jan 21 '11 at 12:02
  • possible duplicate of [PHP & Hash / Fragment Portion of URL](http://stackoverflow.com/questions/1162008/php-hash-fragment-portion-of-url) – Gordon Jan 21 '11 at 12:03
  • Which URL are you trying to parse? The current page's URL, or one you've got from somewhere else? – Gareth Jan 21 '11 at 12:10
  • 1
    I want to get current page's url with anchor. – Chirayu Jan 21 '11 at 12:15
  • 1
    Then the answer is, you can't, not just with PHP. – Gareth Jan 21 '11 at 12:55

3 Answers3

1

The anchor part of a URL never gets sent to the server, so if you are trying to load this information from the current URL it won't be there.

As far as the server is concerned, the URL which is loaded by the browser is http://www.mygridview.com/sephora/index.php?mod=config

It's possible (maybe even likely) that some javascript is using the information in the anchor to restore the state of the page after it was altered using AJAX. In that case, it's the Javascript you'll need to look into to get that anchor information sent to the server

Gareth
  • 133,157
  • 36
  • 148
  • 157
0

You get url and then apply parse function on url. eg::

$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

Output::
Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

this fragment is your requirement. If i'm right then try this n got success. :) Thanks

for get current URL::

function getInstance($uri = 'SERVER')
    {

            if ($uri == 'SERVER')
            {
                if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) {
                    $https = 's://';
                } else {
                    $https = '://';
                }

                if (!empty ($_SERVER['PHP_SELF']) && !empty ($_SERVER['REQUEST_URI'])) {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

                    if (strlen($_SERVER['QUERY_STRING']) && strpos($_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING']) === false) {
                        $theURI .= '?'.$_SERVER['QUERY_STRING'];
                    }
                }
                 else
                 {
                    $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
                    if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
                        $theURI .= '?' . $_SERVER['QUERY_STRING'];
                    }
                }

                $theURI = urldecode($theURI);
                $theURI = str_replace('"', '"',$theURI);
                $theURI = str_replace('<', '&lt;',$theURI);
                $theURI = str_replace('>', '&gt;',$theURI);
                $theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
                $theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);

        }
        echo (string)$theURI;
    }
Manish Trivedi
  • 3,481
  • 5
  • 23
  • 29
  • try this $_SERVER['PATH_INFO'] if not work then see this link http://www.webcheatsheet.com/PHP/get_current_page_url.php – Manish Trivedi Jan 21 '11 at 12:16
  • I have already tried this one. but this is not returning the anchor string. – Chirayu Jan 21 '11 at 12:19
  • @Chirayu No offense but if you had taken the time to use the search function before asking your question, then you'd know that the fragment cannot be retrieved from the Server environment. You have to actively pass it into the script. See the linked question and search results I've put below your question. – Gordon Jan 21 '11 at 12:29
0

Checkout http://www.routesjs.com, you should be able to get the values and send it off with ajax.

TigerMunky
  • 21
  • 4