-1

I am using PHP and want to check links of the same page but with different trailing info.

The URL to the page normally is http://www.mypage.com/?about but if the user accessed it by clicking on the link SEND the user get send to http://www.mypage.com/?about#send

If the user clicked INFO they go to http://mypage.com/?about#info

Question how do I check for # and what comes after it? I tried $_SERVER[query_string] and it shows about#send and I only need to check for what comes after the number sign #.

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
Khalid
  • 194
  • 1
  • 1
  • 7

3 Answers3

0

You can use this code after reading your url :

$s =  $_SERVER[query_string];
$url = explode('#',$s);
echo $url[1];

In this code $url[1] is the value that you want. Split the url by #,makes an array.

Saman Gholami
  • 3,416
  • 7
  • 30
  • 71
0

It's better to do it client side , but here's the php code than can do it:

<?
echo parse_url("http://mypage.com?about#send",PHP_URL_FRAGMENT);
?>
Outout : send
MIIB
  • 1,849
  • 10
  • 21
  • That second part is simply copied from Saman and then slightly modified ... besides, the first part already works (theoretically). – Ja͢ck Mar 03 '13 at 08:21
  • Ok i'm answering more than 5 questions at a time and i was not giving pay much attension to others asnwers . I'm sorry for the similarity but promise me i did not see that. You are right but i did not copied. Look at my profile and the answers that i given in these 20minutes and you will see that im not lying – MIIB Mar 03 '13 at 08:24
  • 2
    Well, at least clean it up so that it doesn't throw notices for undefined constant `query_string` (and use upper case) and undefined index `1` if there's no hash ... which there isn't anyway. – Ja͢ck Mar 03 '13 at 08:26
0

The hash portion (everything that follows the # sign) is never sent to the server and you cannot get in in your PHP script. You can manipulate it only with javascript. This is achieved with the window.location.hash property.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928