Als er vragen zijn over het script, omdat iets niet duidelijk is, stel ze gerust!
Ik heb de functies die bij het installeren niet worden gebruikt eruit gehaald.
<?PHP
error_reporting(E_ALL);
class UserAuthorization extends MySQLi{
private $MySQL_HOST="127.0.0.1";
private $MySQL_USER="root";
private $MySQL_PASS="";
private $MySQL_DB ="cms_db";
private $ADMIN_MAIL="[email protected]";
//If you want to recieve emails from all the errors, just edit the value below to true (without quotes!)
private $mail_admin_on_error=false;
private $instanceName="Website name for error logging (so the admin knows whats site to look at!)";
##########################
private $dbCon; ##
private $RemAdr; ##
private $cookieData; ##
public $returndata; ##
##########################
public function __construct($todo,$data=""){
$this->RemAdr=md5($_SERVER['REMOTE_ADDR']);
$this->cookieData = (isset($_COOKIE[$this->RemAdr])) ? $_COOKIE[$this->RemAdr] : "";
parent::__construct($this->MySQL_HOST, $this->MySQL_USER, $this->MySQL_PASS, $this->MySQL_DB);
if(mysqli_connect_error()){
$this->LogWrite("[".date("d-m-Y H:i:s")."] -> 'Connection error (".mysqli_connect_errno().") ".mysqli_connect_error())."\r\n";
}
$this->$todo($data);
}
public function getdata(){
return $this->returndata;
}
private function LogWrite($data){
if($this->mail_admin_on_error){
mail($this->ADMIN_MAIL,"Error at webserver [".$this->instanceName."]",$data);
}
$fh=fopen("errorLog.txt","a");
if(!fwrite($fh,$data)){
$this->returndata="There went something wrong, a mail has been sent to the Administrator.";
exit();
}else{
die("There was an error, and the errorlog could not be updated. The server administrator has been mailed.");
}
}
private function executeQuery($sql,$type){
$sql=parent::escape_string($sql);
if($type==="get"){
if($res=parent::query($sql)){
$rows=parent::field_count($res);
return $rows;
}else{
$this->LogWrite(stripslashes("[".date("d-m-Y H:i:s")."] -> 'Could not execute mysql \"get\" query'\r\n"));
exit();
return false;
}
}
elseif($type==="send"){
if($res=parent::query($sql)){
$this->LogWrite(stripslashes("[".date("d-m-Y H:i:s")."] -> 'Could not execute mysql \"send\" query'\r\n"));
exit();
return false;
}else{
return true;
}
}else{
$this->LogWrite("[".date("d-m-Y H:i:s")."] -> 'Wrong parameter used on executeQuery function'\r\n");
exit();
return false;
}
}
//...
private function install($data){
$sql1="INSERT INTO tblUsers VALUES('Administrator','".md5($data)."','0')";
$sql2="INSERT INTO tblLoggedIn VALUES('".$this->RemAdr."',1,'".date("Y-m-d H:i:s",strtotime("+3 week"))."')";
if($this->executeQuery($sql1,"send")&&$this->executeQuery($sql2,"send")){
setcookie($this->RemAdr,true,time()+604800);
$this->returndata="Installation succesful!";
return true;
}else{
$this->returndata="Installation failed...";
return false;
}
}
}
?>