getMessage();
echo "n";
exit();
}
/* エラーモードの設定(例外処理を有効) */
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// 古いアクセスデータ削除
// $nextWeek = time() + (7 * 24 * 60 * 60);
$log = LOG;
$day = time() - ($log * 24 * 60 * 60);
$limit = date("Y/m/d", $day);
//var_dump($limit);
$stmt = $dbh->prepare("DELETE FROM `access_tbl` WHERE `date` < '$limit'");
$stmt->execute();
$cols = array();
$stmt = null;
// 現在のURLを取得
if(empty($_SERVER['HTTPS'])){
$http = 'http://';
} else {
$http = 'https://';
}
$this_url = $http.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
// QRコードURL
if (CARRIER == 'pc') {
$QR = '
当サイトは携帯からご覧下さい
 . '&t=J&s=4)
上のQRコードを読み取るか、
URLを携帯に送信してアクセスして下さい。
';
} else {
$QR = '';
}
// 広告が選択されている場合
if (isset($_GET['ad']) && is_numeric($_GET['ad'])) {
$id = $_GET['ad'];
if (isset($_GET['site']) && is_numeric($_GET['site'])) {
$site = $_GET['site'];
} else {
$site = '';
}
// 広告が存在するか確認
$stmt = $dbh->prepare("SELECT `name`, `url`, `tag` FROM `ad_tbl` WHERE `enable` = 'y' AND `id` = '$id'");
$stmt->execute();
$cols = array();
if ($cols = $stmt->fetch(PDO::FETCH_ASSOC)) { // 広告がある
$stmt = null;
$name = decode($cols['name']);
$url = decode($cols['url']);
$tag = decode($cols['tag']);
// アクセスログを残す
if (CARRIER != 'pc') {
// 今日のログがあるか調べる
$today = date("Y/m/d");
$sql = "
SELECT
*
FROM
`access_tbl`
WHERE
`ad_id` = '$id' AND
`site_id` = '$site' AND
`date` = '$today'
";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$cols = array();
$do = 0;
$au = 0;
$sb = 0;
if ($cols = $stmt->fetch(PDO::FETCH_ASSOC)) { // ログがあるのでカウントアップ
$stmt = null;
$access_id = $cols['id'];
$do = $cols['do'];
$au = $cols['au'];
$sb = $cols['sb'];
$count = $cols['count'] + 1;
switch (CARRIER) {
case 'do':
$do += 1;
break;
case 'au':
$au += 1;
break;
case 'sb':
$sb += 1;
break;
}
$sql = "
UPDATE
`access_tbl`
SET
`do` = '$do',
`au` = '$au',
`sb` = '$sb',
`count` = '$count'
WHERE
`id` = '$access_id'";
$stmt = $dbh->prepare($sql);
$stmt->execute();
} else { // ログがないので挿入
$stmt = null;
switch (CARRIER) {
case 'do':
$do = 1;
break;
case 'au':
$au = 1;
break;
case 'sb':
$sb = 1;
break;
}
$sql = "
INSERT INTO `access_tbl` (
`date`,
`ad_id`,
`site_id`,
`do`,
`au`,
`sb`,
`count`
) VALUES (
'$today',
'$id',
'$site',
'$do',
'$au',
'$sb',
'1'
)";
$stmt = $dbh->prepare($sql);
$stmt->execute();
}
$stmt = null;
}
// 広告を画面表示するか否か
if ($_GET['prt'] == 'on' || empty($url)) {
if (empty($tag)) {
$tag = '' . htmlspecialchars($name) . '';
} else {
$tag = preg_replace('/%%NAME%%/i', $name, $tag);
$tag = preg_replace('/%%URL%%/i', $url, $tag);
}
header("Content-Type: text/html; charset=shift_jis\n");
header("Cache-Control: no-cache\n");
require_once 'tmp/page.php';
exit();
} else {
header("Location:$url");
exit();
}
}//広告がない
$stmt = null;
}
header("Content-Type: text/html; charset=shift_jis\n");
header("Cache-Control: no-cache\n");
require_once 'tmp/top.php';
exit();
// ランダムに広告を表示する関数
function print_ad($num) {
// データベース初期設定
try {
$dbh = new PDO('sqlite:admin/'.DB_PATH, '', '');
} catch (PDOException $exception){
echo "PDO生成時:";
echo $exception->getMessage();
echo "n";
exit();
}
/* エラーモードの設定(例外処理を有効) */
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh->prepare("SELECT count(*) AS `cnt` FROM `ad_tbl` WHERE `enable` = 'y'");
$stmt->execute();
$cols = array();
$cols = $stmt->fetch(PDO::FETCH_ASSOC);
$cnt = $cols['cnt'];
$stmt = null;
if ($cnt <= $num) {
$num = $cnt;
} else {
$offset = $cnt - $num;
$offset = rand(0, $offset);
}
$array = range(1 + $offset, $num + $offset);
srand((float)microtime() * 1000000);
shuffle($array);
if ($num == 1) {
$ret = "";
foreach ($array as $value) {
$stmt = $dbh->prepare("SELECT `id`, `name` FROM `ad_tbl` WHERE `enable` = 'y' ORDER BY `id` ASC LIMIT 1 OFFSET " . ($value - 1) . "");
$stmt->execute();
$cols = array();
$cols = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
$ret .= '
'.htmlspecialchars(decode($cols[name])).'';
}
$ret .= "
";
} else {
$ret = "";
foreach ($array as $value) {
$stmt = $dbh->prepare("SELECT `id`, `name` FROM `ad_tbl` WHERE `enable` = 'y' ORDER BY `id` ASC LIMIT 1 OFFSET " . ($value - 1) . "");
$stmt->execute();
$cols = array();
$cols = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = null;
$ret .= '- '.htmlspecialchars(decode($cols[name])).'
';
}
$ret .= "
";
}
return $ret;
}
?>