I have some code that is accessible from several different pages. Based on which page it comes from and which variables it sends, it does slightly different things.
I guess I could write totally new pages for each referring page but really don't want to do that as the functionality is similar.
In the case of errors, I want to redirect back to the referer page. Similarly, upon success I also want to redirect back to the referer page. However, I'd like to add a parameter that describes the error or let's the user know it was a success to distinguish between a failure and success.
Let's say there are two referer pages, emailstory.php?id=231 and emailsignup.php One has a quesion mark and the other doesn't. I want to send the user back to the referer but add error=1. I need some code that appends &error=1 to the first referer but ?error=1 to the second and is robust to many variations.
php
$referer = $_SERVER['HTTP_REFERER'];
$id = $_POST['id'];
$returnpage = $referer."&error=1";
if (!isset($_REQUEST['id'])) {
header("Location:$returnpage");
}
Above would work in some instances but only if there is already a ? launching a querystring
Is there an easy, foolproof way to do this?
Thanks