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?
-
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.Gordon– Gordon2011年01月21日 12:02:22 +00:00Commented Jan 21, 2011 at 12:02
-
possible duplicate of PHP & Hash / Fragment Portion of URLGordon– Gordon2011年01月21日 12:03:16 +00:00Commented 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?Gareth– Gareth2011年01月21日 12:10:12 +00:00Commented Jan 21, 2011 at 12:10
-
1I want to get current page's url with anchor.Chirayu– Chirayu2011年01月21日 12:15:26 +00:00Commented Jan 21, 2011 at 12:15
-
1Then the answer is, you can't, not just with PHP.Gareth– Gareth2011年01月21日 12:55:25 +00:00Commented Jan 21, 2011 at 12:55
3 Answers 3
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
-
2@Shakti Singh: You cannot
parse_url()
the current page's URL to get the fragment, only a given URL string.BoltClock– BoltClock2011年01月21日 12:06:25 +00:00Commented Jan 21, 2011 at 12:06 -
@BoltClock: I thought that like he is fetching the url from DB or any other resourceShakti Singh– Shakti Singh2011年01月21日 12:13:21 +00:00Commented Jan 21, 2011 at 12:13
-
@Shakti the clarification in the comments above shows that he isn'tGareth– Gareth2011年01月21日 12:54:52 +00:00Commented Jan 21, 2011 at 12:54
-
@Gareth: Cool dude he posted at later time. No worriesShakti Singh– Shakti Singh2011年01月21日 12:57:09 +00:00Commented Jan 21, 2011 at 12:57
Checkout http://www.routesjs.com, you should be able to get the values and send it off with ajax.
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('<', '<',$theURI);
$theURI = str_replace('>', '>',$theURI);
$theURI = preg_replace('/eval\((.*)\)/', '', $theURI);
$theURI = preg_replace('/[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']/', '""', $theURI);
}
echo (string)$theURI;
}
-
try this $_SERVER['PATH_INFO'] if not work then see this link webcheatsheet.com/PHP/get_current_page_url.phpManish Trivedi– Manish Trivedi2011年01月21日 12:16:03 +00:00Commented Jan 21, 2011 at 12:16
-
I have already tried this one. but this is not returning the anchor string.Chirayu– Chirayu2011年01月21日 12:19:00 +00:00Commented 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.Gordon– Gordon2011年01月21日 12:29:43 +00:00Commented Jan 21, 2011 at 12:29