prepare('SELECT * FROM user WHERE user_id = ?'); $req->execute(array($_POST['configuration_username'])); $data = $req->fetch(); // Error ? if($data && passEqual($_POST['configuration_pass'], $data['user_pass'])) { // Thanks http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php if($_POST['configuration_os'] == "gnu_linux") { $conf_dir = 'gnu-linux'; } else { $conf_dir = 'windows'; } $rootPath = realpath("./client-conf/$conf_dir"); // Initialize archive object $archive_base_name = "openvpn-$conf_dir"; $archive_name = "$archive_base_name.zip"; $archive_path = "./client-conf/$archive_name"; $zip = new ZipArchive(); $zip->open($archive_path, ZipArchive::CREATE | ZipArchive::OVERWRITE); $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY ); foreach ($files as $name => $file) { // Skip directories (they would be added automatically) if (!$file->isDir()) { // Get real and relative path for current file $filePath = $file->getRealPath(); $relativePath = substr($filePath, strlen($rootPath) + 1); // Add current file to archive $zip->addFile($filePath, "$archive_base_name/$relativePath"); } } // Zip archive will be created only after closing object $zip->close(); //then send the headers to foce download the zip file header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=$archive_name"); header("Pragma: no-cache"); header("Expires: 0"); readfile($archive_path); } else { $error = true; } } // Admin login attempt ? else if(isset($_POST['admin_login'], $_POST['admin_username'], $_POST['admin_pass']) && !empty($_POST['admin_pass'])){ $req = $bdd->prepare('SELECT * FROM admin WHERE admin_id = ?'); $req->execute(array($_POST['admin_username'])); $data = $req->fetch(); // Error ? if($data && passEqual($_POST['admin_pass'], $data['admin_pass'])) { $_SESSION['admin_id'] = $data['admin_id']; header("Location: index.php?admin"); exit(-1); } else { $error = true; } } ?>