I am currently working on a form that displays email address and other details of the member when user is posting an advert. Understanding this is not an ideal world where things always happen according your plan, I wd like to be able to destroy session and redirect user to sign-in page when someone is tampering with email address field. I have managed to destroy the session but while redirecting url is playing up as per below.
FORM URL: http://localhost:8080/advert_post_Off.php?productid=31380&advertid=201246998
Expected signin page URL:http://localhost:8080/signin.php?redirect=authenticationerror
Redirect URL: http://localhost:8080/signin.php?redirect=advert_post_Off.php?productid=31380&advertid=201246998
PHP Code
$q = "SELECT * FROM users where email='$_SESSION[username]'";
$r = mysqli_query($dbc, $q) or die(mysql_error());
$row = mysqli_fetch_assoc($r);
$email = $row['email'];
$email_posted = $_POST['inputemail'];
if($email === $email_posted) {
if(isset($_POST['postad'])) {
// Insert form data into URL
}
} else {
unset($_SESSION['username']);
session_destroy();
header('Location:/signin.php?redirect=authenticationerror');
}
Please help how could I redirect properly so that the URL will look as per expectation.