What do I need to put in a php code so that the user cannot access it even if he specified the correct url for the page they are trying to access. And redirect it to the logon page. I'm really having difficulty in this matter, everytime I click back button on the browser the user can still access the page
A:
if (...) {
header('Location: http://www.example.com/');
exit 0;
}
Just make a proper if clause.
http://php.net/manual/en/function.header.php
PS: Ty Michael
Rui Carneiro
2010-05-21 08:36:55
You probably want an `exit;` after the `header()` call, or the rest of the script will still get executed
Michael Mrozek
2010-05-21 08:39:31
A:
If you require/include your from within any other php file like an index.php, then, you can define a constant which will be checked against in your required file.
index.php:
define(APP_LOADED, true);
required_file.php:
if ( !defined(APP_LOADED) ) {
header('Location: login.php');
exit 0;
}
// do something else here
Boris Guéry
2010-05-21 08:37:31
+1
A:
You need to implement some kind of ACL check. Basic solution would be to set SESSION upon logging in.
If user accesses some page he shouldn't see, you just redirect him back to login page.
if ( !isset( $_SESSION[ "login" ] && ... ) {
header( "Location: path_to_login_page" );
}
Ondrej Slinták
2010-05-21 08:40:00