-1

I have a URL of the form:- http://www.sboxeppp.com:88/phones.php?iden=true#6786

Now i want to retrieve number (6786) followed by # in server side. How can i do that?

Mike
  • 51
  • 1
  • 6
  • `window.location.hash` should work. See: http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript – rickyduck Sep 13 '11 at 10:27
  • possible duplicate of [PHP & Hash / Fragment Portion of URL](http://stackoverflow.com/questions/1162008/php-hash-fragment-portion-of-url) – Gordon Sep 13 '11 at 10:36

5 Answers5

1

anything behind the hash can only be accessed by client side scripts, since it won't be sent to the server you can use the parse_url() function

more here: http://php.net/manual/en/function.parse-url.php

0

You cannot do that. The part of the url after the hash is called a fragment, and it does not get sent to the server. It's only available to client scripting.

The only way that you could do this is by retrieving the fragment from JavaScript (using window.location.hash) and communicating this information to the server with an AJAX request specifically made for this purpose. Of course this means that the server will have to render the page first and get notified of the fragment later, which is a totally different workflow than what you want.

Jon
  • 428,835
  • 81
  • 738
  • 806
0

You can't do that, because it's a directive for browser only. You can use AJAX requests to send the required info to server.

haynar
  • 5,961
  • 7
  • 33
  • 53
0

Use parse_url:

parse_url('http://www.sboxeppp.com:88/phones.php?iden=true#6786',
          PHP_URL_FRAGMENT);

Notice that the fragment doesn't get sent to the server if it's in the form's target property. Instead, just write the information in the fragment in a hidden element, like this:

<input type="hidden" name="_fragment" value="6786" />

And read the fragment from $_POST['_fragment'].

If the fragment is generated client-side (or somehow determined by the user), you'll have to create that element on the client. You can access the current fragment in JavaScript with window.location.hash.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • He doesn't have a URL with a fragment to begin with, though. – Jon Sep 13 '11 at 10:30
  • @Jon Added information on how to retrieve the URL. `I have a URL of the form: http://www.sboxeppp.com:88/phones.php?iden=true#6786` sounds like he has though, and `parse_url` might be a relevant answer for future visitors of this question. – phihag Sep 13 '11 at 10:35
0

Right, it didnt let me post that as an answer -

var hashNumber = window.location.hash should work.

hashNumber = hashNumber.substring(1)

See:

How can you check for a #hash in a URL using JavaScript?

Community
  • 1
  • 1
rickyduck
  • 4,030
  • 14
  • 58
  • 93