I have an error page which, I would like to call from more than one pages in my site. In this error page, I pass a message(using the url for now), but I would also like to pass a link of a page too.
The error page will use this link to redirect the user to the page I want. I have thought to pass the link using sessions or having a form(method post) with hidden input. Which one is better? And is there any other way to do that?
Thank you in advance!
You're looking for $_SERVER['HTTP_REFERER'];
which is one of PHP's $_SERVER predefined variables...
More can be read here
tl;dr
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
I think,you must use HTTP referer...
Have you tried $_SERVER['HTTP_REFERER']
.
I have read it is not very trust worthly, but worth an attempt.
You can try this approach:
Your Normal file:
<?php
$_SESSION['message'] = 'your message here';
$_SESSION['redirect_url'] = 'your page url here'; // this will allow you to redirect the user to any url of your choice and not just the referrer.
header('Location: error.php');
?>
error.php:
<?php
echo $_SESSION['message'];
?>
<html>
<head>
<meta http-equiv="refresh" content="2;url=<?php echo $_SESSION['redirect_url'];?>">
</head>
</html>
Hope this helps.