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.9k29 gold badges183 silver badges239 bronze badges
asked Jan 21, 2011 at 11:55
5
  • 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, so you should point out which of those approaches you have tried and why it's still not working. Commented Jan 21, 2011 at 12:02
  • possible duplicate of PHP & Hash / Fragment Portion of URL Commented Jan 21, 2011 at 12:03
  • Which URL are you trying to parse? The current page's URL, or one you've got from somewhere else? Commented Jan 21, 2011 at 12:10
  • 1
    I want to get current page's url with anchor. Commented Jan 21, 2011 at 12:15
  • 1
    Then the answer is, you can't, not just with PHP. Commented Jan 21, 2011 at 12:55

3 Answers 3

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

answered Jan 21, 2011 at 11:58
4
  • 2
    @Shakti Singh: You cannot parse_url() the current page's URL to get the fragment, only a given URL string. Commented Jan 21, 2011 at 12:06
  • @BoltClock: I thought that like he is fetching the url from DB or any other resource Commented Jan 21, 2011 at 12:13
  • @Shakti the clarification in the comments above shows that he isn't Commented Jan 21, 2011 at 12:54
  • @Gareth: Cool dude he posted at later time. No worries Commented Jan 21, 2011 at 12:57
0

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

answered Jan 21, 2011 at 12:03
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;
 }
answered Jan 21, 2011 at 12:01
3
  • try this $_SERVER['PATH_INFO'] if not work then see this link webcheatsheet.com/PHP/get_current_page_url.php Commented Jan 21, 2011 at 12:16
  • I have already tried this one. but this is not returning the anchor string. Commented Jan 21, 2011 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. Commented Jan 21, 2011 at 12:29

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.