function initialize_page() { // If the user requested the login page but has a bookmarked place to go (or they were logged out while working) $optionalredirect = ""; if (getRequestVarAtIndex(1) != "" && getRequestVarAtIndex(1) != " " && getRequestVarAtIndex(1) != "login") { $optionalredirect .= getRequestVarAtIndex(1); } if (getRequestVarAtIndex(2) != "" && getRequestVarAtIndex(2) != " ") { $optionalredirect .= "/" . getRequestVarAtIndex(2); } if (getRequestVarAtIndex(3) != "") { $optionalredirect .= "/" . getRequestVarAtIndex(3); } if (getRequestVarAtIndex(4) != "") { $optionalredirect .= "/" . getRequestVarAtIndex(4); } if (getRequestVarAtIndex(5) != "") { $optionalredirect .= "/" . getRequestVarAtIndex(5); } if (getRequestVarAtIndex(6) != "") { $optionalredirect .= "/" . getRequestVarAtIndex(6); } if (Users::GetCurrentUser()) { // If the user is still logged in and they hit this page, redirect them to the homepage or somewhere else redirect("/admin" . $optionalredirect); } $post_action = ""; if (isset($_POST['submit'])) { $post_action = $_POST['submit']; } if ($post_action == "Login") { $email = $_POST['email']; $password = $_POST['password']; if ($email == "" || $password == "") { setFlash("<h3>Please enter a username and password</h3>"); } else { $user = Users::FindByEmail($email); if (is_object($user)) { /* Check to see if we are in maintenance mode */ if (MAINTENANCE_MODE) { if ($user->email != "*****@*****.**") { setFlash("<h3>We are sorry, the site is in maintenance mode right now. Please try to log-in later.</h3>"); } else { if ($user->authenticate($password)) { $user->set_ticket(); setFlash("<h3>Thank you for logging in during Maintenance Mode, Admin</h3>"); redirect(Users::GetRedirect("/admin/" . $optionalredirect)); } } } else { if ($user->authenticate($password)) { $user->set_ticket(); // Backup database on successful Log in $params = @parse_url(MYACTIVERECORD_CONNECTION_STR) or trigger_error("MyActiveRecord::Connection() - could not parse connection string: " . MYACTIVERECORD_CONNECTION_STR, E_USER_ERROR); $backupDatabase = new Backup_Database($params['host'], $params['user'], $params['pass'], trim($params['path'], ' /')); $success = $backupDatabase->backupDatabase(SERVER_DBBACKUP_ROOT, 5) ? 'The database has been archived.' : 'The database archive FAILED.'; setFlash("<h3>Thank you for logging in. {$success}</h3>"); redirect(Users::GetRedirect("/admin/" . $optionalredirect)); } else { $_SESSION[LOGIN_TICKET_NAME] = NULL; setFlash("<h3>User not found, or password incorrect</h3>"); } } } } } }
/** * This file contains the Backup_Database class wich performs * a partial or complete backup of any given MySQL database * @author Daniel López Azaña <http://www.daniloaz.com> * @version 1.0 * http://www.daniloaz.com/en/560/programming/backup-de-bases-de-datos-mysql-con-php/ */ /** * Define database parameters here */ define("OUTPUT_DIR", '../unused/sqldmp'); define("TABLES", '*'); /** * Instantiate Backup_Database and perform backup */ $backupDatabase = new Backup_Database(SERVER, USERNAME, PASSWORD, DATABASE); $status = $backupDatabase->backupTables(TABLES, OUTPUT_DIR) ? 'OK' : 'KO'; echo "<br /><br /><br />Backup result: " . $status; /** * The Backup_Database class */ class Backup_Database { /** * Host where database is located */ var $host = ''; /** * Username used to connect to database */ var $username = '';
<?php require_once './conexion.php'; $usuario = 'root'; $password = ''; $db = 'db_farmacia'; $local = 'localhost'; $tables = '*'; $dir = 'd:backup'; /** * Instantiate Backup_Database and perform backup */ $backupDatabase = new Backup_Database($local, $usuario, $password, $db); $status = $backupDatabase->backupTables($tables, $dir) ? 'OK' : 'KO'; echo "\n\n\nBackup result: " . $status; /** * The Backup_Database class */ class Backup_Database { /** * Host where database is located */ var $host = ''; /** * Username used to connect to database */ var $username = ''; /** * Password used to connect to database */
$sendMailer->AddAddress('*****@*****.**'); //$sendMailer->AddAddress('*****@*****.**'); $sendMailer->Subject = "Daily Sales Email Report"; $sendMailer->IsHTML(true); $sendMailer->Body = date('d/m/Y H:i:s') . "\n<table border='0'>\n<tr>\n\t<td>Daily </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['d']}</td>\n</tr>\n<tr>\n\t<td>Weekly </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['w']}</td>\n</tr>\n<tr>\n\t<td>Monthly</td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['m']}</td>\n</tr>\n<tr>\n\t<td>Yearly </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['y']}</td>\n</tr>\n</table>"; $result['mailsales'] = 'sending'; try { $sent = $sendMailer->Send(); if ($sent) { $result['mailsales'] = 'sending success'; $result['text'] .= ' sales figure sent.'; } else { $result['mailsales'] = 'sending failed'; } } catch (phpmailerException $e) { $result['mailsales'] = $e->errorMessage(); } catch (Exception $e) { $result['mailsales'] = $e->getMessage(); } if (!$result['exists']) { include 'mysql-backup.php'; $dbbackup = new Backup_Database($server, $user, $pass, $db, 'utf-8'); $status = $dbbackup->backupTables('*', 'localhost', $backupname, $log); $result['result'] = $status; } else { $result['result'] = false; } if (!$log) { header('Content-type: application/json'); } echo json_encode($result);
protected function saveFile(&$sql, $outputDir = '.') { if (!$sql) { return false; } try { $handle = fopen($outputDir . '/' . $this->dbName . '-' . date("dmY-His") . '.sql', 'w+'); fwrite($handle, $sql); fclose($handle); } catch (Exception $e) { var_dump($e->getMessage()); return false; } return true; } } /** * Instantiate Backup_Database and perform backup */ $backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $status = $backupDatabase->backupTables(TABLES, OUTPUT_DIR) ? 'Concluído' : 'ERRO'; echo "\n<hr/><p>\nBackup " . $status . '!'; echo '<p>Salvo em : <b>' . OUTPUT_DIR . '</b></p>'; echo '<br/>'; echo '<a href="principal.php" class="btn btn-success">Voltar</a>'; } else { header('Location: principal.php'); } if ($_SESSION["logado"] == false) { header('Location: logout.php'); }
<?php define("DB_USER", 'root'); define("DB_PASSWORD", ''); define("DB_NAME", 'be'); define("DB_HOST", 'localhost'); define("TABLES", '*'); $backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $backupDatabase->backupTables(TABLES); class Backup_Database { var $host = 'localhost'; var $username = '******'; var $passwd = ''; var $dbName = 'be'; var $charset = ''; //set variables to connect to database function Backup_Database($host, $username, $passwd, $dbName, $charset = 'utf8') { $this->host = $host; $this->username = $username; $this->passwd = $passwd; $this->dbName = $dbName; $this->charset = $charset; $this->initializeDatabase(); } //connect to database protected function initializeDatabase() { $conn = mysql_connect($this->host, $this->username, $this->passwd); mysql_select_db($this->dbName, $conn);