0
http://localhost/mysite/#id=98b7ee047f0a4fd6530d2538f7f929cc&com=289916

I need to get values of 'id' and 'com'. I have to put '#' symbol in front parameter, because I need the page without refreshing itself.

6339
  • 475
  • 3
  • 16
  • PHP can't do this as it it server-side only, and URL hashes are only client-side and are never sent to the server. You can however use JavaScript to get the hash and then send it to server via AJAX. – kittycat Feb 28 '13 at 06:34

2 Answers2

0

Try this :

$url = 'http://localhost/mysite/#id=98b7ee047f0a4fd6530d2538f7f929cc&com=289916';

echo "<pre>";
print_r(parse_url($url));

Output :

Array
(
    [scheme] => http
    [host] => localhost
    [path] => /mysite/
    [fragment] => id=98b7ee047f0a4fd6530d2538f7f929cc&com=289916
)
Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
  • seems good solution but how did you get the url? – 6339 Feb 28 '13 at 06:32
  • 2
    This is for parsing a URL string, not for getting the current page's hash which is what I think the OP is wanting. – kittycat Feb 28 '13 at 06:33
  • @crypticツ, @Deepu : I understood the problem, If you have control over generation of url, pass it as a query string, and if you really want a hash put it at the end of query string : something like this :`http://domain.com?q=querystring#hash` – Prasanth Bendra Feb 28 '13 at 06:37
  • @PrasanthBendra that won't work because if you want it to be sent to the server you would need to encode the `#` at which point it is no longer a hash and the browser will refresh the page when such a link is clicked. – kittycat Feb 28 '13 at 06:39
  • @crypticツ : OK, then i guess he need to use javascript `window.location.hash` and to send it to server use AJAX – Prasanth Bendra Feb 28 '13 at 06:43
  • @crypticツ, @ PrasanthBendra: Yep, i'm gonna use Ajax. Thanks buddy – 6339 Feb 28 '13 at 06:52
-1

For getting the url you can use

$url = $_SERVER['REQUEST_URI'];

then you can apply the above method Quoted by Prasanth Bendra.

echo ""; print_r(parse_url($url));

X-Factor
  • 2,067
  • 14
  • 18