need help on php require
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 l开发者_开发知识库ogon page. I'm really having difficulty in this matter, everytime I click back button on the browser the user can still access the page
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" );
}
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
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
精彩评论