How to get the current Browser URL with PHP?

Asked

Viewed 1,704 times

1

For example, I have the following URL generated with ngRoute of AngularJS: https://www.projeto.com/edit/25, 25 is the ID, I need to get this ID in PHP.

In researches, I found the following solution to get the URL in PHP:

$url = $_SERVER[REQUEST_URI]

But the problem is that it returns the wrong URL, returns https://www.projeto.com/edita.php instead of the angular generated URL (https://www.projeto.com/edit/25).

Is there any way to get the current browser URL in php?

  • Give a print_r($_SERVER) and see the options the server has. I believe the value you want will be in the list.

  • @Brunorigolon Thanks! There you have the option HTTP_REFERER which is exactly what I need. Put the answer in the question. :)

  • It would be very interesting also for you to post here the . htaccess rules for the URL rewriting.

1 answer

1


Use the $_SERVER['HTTP_REFERER'] attribute, it will reference the request source link.

  • Just remembering that this is dangerous, never trust the headlines, anyone can change that information. Even many privacy plugins/extensions do not even send this information.

  • Thanks for the tip @Inkeliz

Browser other questions tagged

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