0

I'm new to php. I'd like to know if there is a way to retrieve the page who sent the request.

Let's say I have a file called Page.php with the following bit of code:

<form action="script.php" method="post">...</form>

Is there some way to dynamically get the value "Page.php" on script.php?

Eduardo
  • 277
  • 1
  • 6
  • 17
  • Put it in a hidden field and submit it. You can't necessarily rely on referrers – Machavity Dec 13 '16 at 14:47
  • 2
    Depends on how reliable you need it to be. You can check the referrer header or perhaps put a hidden form field and check that, both of which can be spoofed by the user. – David Dec 13 '16 at 14:47
  • [debug_backtrace](http://php.net/manual/en/function.debug-backtrace.php) – mister martin Dec 13 '16 at 14:49
  • @Machavity That dupe, is not a reliable method, and here's why http://stackoverflow.com/a/6023980/1415724 – Funk Forty Niner Dec 13 '16 at 14:49
  • @Fred-ii- Yeah, I mentioned that in my comment. if you think it needs to be a different dupe, feel free to change it – Machavity Dec 13 '16 at 14:59
  • Put a hidden field in your HTML form with the `$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']` to get the full URL of the submitting form. This, just like `HTTP_REFERER` can be manipulated by the user so should not be relied upon. I would suggest authenticating the value, but that's way outside the scope of this Q – Martin Dec 13 '16 at 14:59
  • @Machavity I think there are quite a few ways to do this actually. However, I said it was not reliable, I didn't say it was wrong; 2 different animals here ;-) – Funk Forty Niner Dec 13 '16 at 15:02
  • Hmm, thanks for commenting. Sorry if it is a duplicate I did not know how to phrase my question to php specific stuff. – Eduardo Dec 13 '16 at 16:03

1 Answers1

0

$_SERVER['HTTP_REFERER'] will give you the referrer page's URL if there exists any. More information here: PHP: How to get referrer URL?

Please note that using HTTP_REFERER isn't reliable, it's value is dependent on the HTTP Referer header sent by the browser or client application to the server. More information here: How reliable is HTTP_REFERER? In other words it can't be trusted but it can help you :).

Community
  • 1
  • 1
rap-2-h
  • 30,204
  • 37
  • 167
  • 263