Friday, August 3, 2018

Create Auto Backup Database on Linux


apt-get install cron

crontab -e

#!/bin/sh
 mysqldump -u root -pQidDniuJMb@LC@G5 gift > /var/bin/db/gift/gift.sql
 cd /var/bin/db/gift/
 tar -zcvf giftsql_$(date +%d%m%y).tgz *.sql
 find -name '*.tgz' -type f -mtime +2 -exec rm -f {} \;

0 * * * * /var/bin/mysqlbackup.sh


*/3 * * * * /var/bin/executedb.sh

Thursday, August 2, 2018

Basic Auth with PHP


// basic auth
if (
   !isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) ||
   ($_SERVER['PHP_AUTH_USER'] !== 'admin' && $_SERVER['PHP_AUTH_PW'] !== 'test')) {
    header('WWW-Authenticate: Basic realm="Enter username and password for admin page."');
    header('Content-Type: text/plain; charset=utf-8');
    die('このページを見るにはログインが必要です。');
    header('Content-Type: text/html; charset=utf-8');
}