I have this contact form. I want that after filling the form and clicking the submit button, my script checks if the user is logged in. If the user is not logged in, he is redirected to the login page to login and after that, he sees a 'thanks for filling the form'. I don't know how to do this, my script redirects the user back to an empty contact form after login and then the user will once again, have to fill the fields. How do i solve this? 

contact.php

```
<?php
session_start();
$location= urlencode($_SERVER['REQUEST_URI']);
if (isset($_SESSION['id']) == false){
    echo "You have to be <a href='login.php?location=$location'>logged in</a>";
}else{
//Insert into database 
//thanks for filling the form
}
?>
//Contact form fields

```

login.php

```
<?php
if (login details is true) {
             $redirect = NULL;
             $redirect = $_GET['location'];
             header("Location:". $redirect);
}
?>

```