this is my first stack overflow question. I have a home page, where you can login, if you login it sends you to a login php in which you have some code that checks if login is incorrect. If that is the case this code redirects you back to home page:
header("Location: ".SERVER_ADDRESS."home?error=invalid_login");
Now you are back on the home page but the url variable is not set. It does not show in a
var_dump(parse_url($_SERVER['HTTP_REFERER'])); or
var_dump($_GET);
This is my index.php file:
<?php
session_start();
require_once("config.php");
if(!(isset($_GET['page']))) { // redirect to main page
header("Location: ".SERVER_ADDRESS."home");
} else {
$mp = new MainPage($_GET['page']); // redirect to given page
}
?>
If you go try login again with wrong credentials and do the same redirection process it will now show the variable. Same thing happens if I were to refresh the header after few seconds.
I seem to not understand why the home page would not show the variable straight away, I just want to use the variable for an if statement that would print an extra invalid login message.
I am using wampserver64 for localhosting.
My .htaccess looks like this:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9a-zA-Z\-\#]+)/?$ index.php?page=$1 [L]
EDIT: CBroe's answer helped me, my htaccess did not have a QSA flag
home, and rewrites the request to/index.php?page=home. You need to add the QSA flag - query string append - to get the new query string you are creating there, merged with any existing one.#in your rule pattern character class is pretty superfluous by the way, you will never encounter that character in a URL path. (RewriteRule only matches against the path component of the URL.)var_dump(parse_url($_SERVER['HTTP_REFERER']after the initial login:'scheme' => string 'http' (length=4) 'host' => string 'localhost' (length=9) 'path' => string '/gra/home' (length=9)after second time:'scheme' => string 'http' (length=4) 'host' => string 'localhost' (length=9) 'path' => string '/gra/home' (length=9) 'query' => string 'error=invalid_login' (length=19)