Search code examples
phphttp-redirectheaderreferer

How to get the referring filename from a request in PHP


I'm building the finishing touches on the registration aspect of my web application and am scratching my head on how I'm going to display a "success" message.

I've decided that I will redirect using:

header("Location: account.php", true, 303);

Once I've done that, I've decided to check the referring filename (and GET variable) to make sure it came from "account.php?action=processregister".

I'm wondering, how might I write code to retrieve the filename (and variables) that processed the redirect?

If you require more information, such as code, feel free to ask.

UPDATE

Found this after some digging on Google, could be useful to other askers: https://github.com/plasticbrain/PHP-Flash-Messages


Solution

  • To get the refferer $_SERVER['HTTP_REFERER']; from here http://php.net/manual/en/reserved.variables.server.php

    For your question, i think you need to store some data in $_SESSION.

    For example, $_SESSION['flash-message'] = 'Registration done successefull!';