I have the below PHP code:
<?php
// let's add a ref url feature for quick guidance.
$ref = $_SERVER['HTTP_REFERER'];
$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]?ref=$ref";
header("Location: $actual_link");
if (empty($ref)) {
# do nothing...
} else {
$redirect_to_ref = header("Location: $ref");
header("Location: test.php");
}
}
?>
<?php
function checkRef() {
if (isset($redirect_to_ref)) {
$redirect_to_ref;
} else {
header("Location: index.php");
}
}
$error = false;
if(isset($_POST['login'])){
$username = htmlspecialchars($_POST['username']);
$password = md5($_POST['password']);
if(file_exists('users/' . $username . '.xml')){
$xml = new SimpleXMLElement('users/' . $username . '.xml', 0, true);
if($password == $xml->password){
session_start();
$_SESSION['username'] = $username;
checkRef();
die;
}
}
$error = true;
}
?>
This code is for a simple xml login script. This will just log the person in, and if the person came from a page that required one to be logged in, but one wasn't, I would like it to add the referrer in the url bar, and upon login success, redirect the user to that referred url. However, this is now giving me an error 500. Please help...