3

My links are like this

http://sitename.com/test/t9.html#post23

I want to get the full link from the browser, or get only number of the post from it

I've tried:

$_SERVER['SERVER_NAME'];
$_SERVER['REQUEST_URI'];

But this show me only before the hash

http://sitename.com/test/t9.html#post23

i want get all link or the number after hash 23

Charles
  • 50,943
  • 13
  • 104
  • 142
o6 qr
  • 95
  • 2
  • 7
  • 3
    Everything after the hash is not sent to PHP. You'd need to use javascript to utilize / send it to PHP. – rfoo Mar 15 '14 at 00:27
  • "parse_url" that is working good , but how i get all link to use it parse_url("http://sitename.com/test/t9.html#post23",PHP_URL_FRAGMENT); – o6 qr Mar 15 '14 at 01:33

2 Answers2

0

The anchor (#) section of the URL is not passed through to PHP, so you'll be unable to get access to it as you're expecting.

You'll need to use javascript to grab it like this:

<script>alert(window.location.hash);</script>

And perhaps then use ajax to send that through to your PHP

duellsy
  • 8,497
  • 2
  • 36
  • 60
  • thnx brother ,i'm not good in ajax ... can you write all code or another way to get post number – o6 qr Mar 15 '14 at 00:51
  • How about you try and write the code yourself? This isn't a place to just ask for code. – Rimble Mar 15 '14 at 01:54
  • thnx brother , i already write all my code but only this part is a problem for me . and i said to you i'm not good in ajax , so how i write something i don't know about it – o6 qr Mar 15 '14 at 02:11
  • tbh when you need the anker in your php script you've done something wrong. – Pinki Mar 15 '14 at 14:36
  • @Pinki , Yeah but this script not mind " i'm not make it " – o6 qr Mar 15 '14 at 21:11
0

$_SERVER['QUERY_STRING']; should actually work i think ;)

Pinki
  • 1,042
  • 9
  • 17