Skip to content
Advertisement

Get the current URL #ID in PHP

People, i’ve tried many tutoriais but none of then seens to work for me, maybe I’m doing something wrong, not sure, but let’s go.

I’ve this page with some visible and not visible content. They are controled by a menu, which triggers a function that displays and hides the content. Ex: Life, Economy and Hardware. If the user clicks on Economy, all Economy articles and tab options will become visible as the other ones, be hided. That’s is working just fine, but, on my homepage there are also some buttons with this options (life, economy and hardware) that shares a URL and directs the user to this page with an URL #ID argument:

<button href="mysite.com/exams/articles/#v-pills-1">
<button href="mysite.com/exams/articles/#v-pills-9">
<button href="mysite.com/exams/articles/#v-pills-17">

How can I make this /life.php page get the #v-pills-0 ID on the URL and identify the number, so I can work a function based on it? Thank you very much for any response.

Advertisement

Answer

Done it!

Thanks to the steven7mwesigwa comment, thanks bro!

I changed the button href to:

<button href="mysite.com/exams/articles/?id=v-pills-1#v-pills-1">

Mantaining the #ID funcionality and making it possible to get the id= with PHP, since steven said PHP can’t get the #value without the ?= parameter.

And used the following PHP code that I’ve tried before but didn’t work.

$argumento = $_GET['id'];

Thanks to everyone.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement