I have a question and answers site. I have an admin section. From that section I can delete users, threads, responses, and edit various other things. I have some simple code at the start of the admin page:
if(($session->protected_page_security()) == FALSE ||
($session->is_administrator() == FALSE)){
$session->logout;
redirect_to('../index.php');
}
A session class has the following methods....
public function protected_page_security() {
if(!$this->confirm_session_is_valid() && !$this->check_login()){
return false;
} else {
return true;
}
}
public function confirm_session_is_valid() {
$check_ip = true;
$check_user_agent = true;
$check_last_login = true;
if($check_ip && !$this->request_ip_matches_session()) {
return false;
}
if($check_user_agent && !$this->request_user_agent_matches_session()) {
return false;
}
if($check_last_login && !$this->last_login_is_recent()) {
return false;
}
return true;
}
public function request_ip_matches_session() {
if(!isset($this->ip) || !isset($_SERVER['REMOTE_ADDR'])) {
return false;
}
if($this->ip === $_SERVER['REMOTE_ADDR']) {
return true;
} else {
return false;
}
}
public function request_user_agent_matches_session() {
if(!isset($_SESSION['user_agent']) || !isset($_SERVER['HTTP_USER_AGENT'])) {
return false;
}
if($_SESSION['user_agent'] === $_SERVER['HTTP_USER_AGENT']) {
return true;
} else {
return false;
}
}
public function last_login_is_recent() {
$max_elapsed = 60 * 60 * 24; // 1 day
// return false if value is not set
if(!$this->last_login) {
return false;
}
if(($this->last_login + $max_elapsed) >= time()) {
return true;
} else {
return false;
}
}
public function is_administrator(){
$administrator_ids = array("164");
if(in_array($_SESSION['user_id'], $administrator_ids)){
return true;
} else {
return false;
}
}
USER_ID = "164" is an administrator.
My question is this:
Do you think it is unwise to have a link to the admin section on the site (even if only shown for me, when I log in)? If someone can gain access to this page, they can bring down the entire database. Is it wiser to not have any link and just type the address in as a url?
I apologise for the simple question -
I am guessing it is possible for someone to find out (hack) the site file structure and "see" that there is an admin section regardless of whether there is any link to it right so maybe my question is moote.