Catch anchor url with PHP

Asked

Viewed 1,225 times

2

I need to get the data from an anchor in the url, follow link:

http://192.168.110. 4/newspaper/1-jornal1#8

I need that one ID 8 that is at the anchor, the problem is that I can’t use Javascript to catch it.

I need to use only PHP.

I am using Codeigniter, however, if I use $this->uri->segment(), he does not recognize the anchor as a segment.

  • 1

    PHP will not get this information anyway. This information is specific to the browser as far as I knew. If you want something for PHP, why not use a GET? If this is the case, you can also use AJAX

  • 1

    This is only possible with Javascript, or with Javascript + PHP, because PHP is server side, that is, it only captures information that is processed on the server side.

2 answers

3


This is not possible. As this value is never sent to the served, it will not be available at $_SERVER['REQUEST_URI'] or similar predefined variables.

You would need some kind of "magic" on the client side (for example, using Javascript), to pass this value to PHP.

The original response was taken from SOEN

One of the possible solutions would be to use Ajax or passing the desired value to a url parameter as well.

Leaving your url with something like this:

http://192.168.110.4/jornal/1-jornal1?id=5#8

Why not? So you would support Javascript and PHP.

-2

It seems to me that each segment is divided by '/', so it is normal that it does not recognize '#' as a segment delimiter.

The following should work. First extract the segment and then isolate the id you want.

$segment = $this->uri->segment(2); //obter o segmento
preg_match("/#([0-9]*)/", $segment, $matches); //isolar o id
$id = !empty($matches[1]) ? (int) $matches[1] : null; // verificar se este existe

Browser other questions tagged

You are not signed in. Login or sign up in order to post.