I am currently using PHP/MySQL, and I’d like to know the best way make an unauthenticated user login, and then have them automatically redirected to the page they logged in.
For example:
1) User tries to open up secure page.
2) They’re re-directed and prompted to login.
3) After they login successfully, they’re taken back to the URL they were trying to access.
Currently, on my “secure” pages, I have the following PHP code set up: (Not even sure if this is the proper way to do ‘secure’ it):
<?php
session_start();
if ($_SESSION['first'] == "" && $_SESSION['usrID'] == "") {
print" <script>
window.location=\"../login/index.php\"
</script> ";
}
?>
Any suggestions on how to provide this feature (and possibly make my ‘secure’ code better), I’d greatly appreciate it.
Thanks!
You could store the requesting URL in a session var.
Then, once logging in, you could do something like this:
Also, this isn’t such a good idea
Using JavaScript to redirect has problems. For one, nothing will happen with JavaScript disabled. Try sending location headers