Created
February 9, 2015 18:29
-
-
Save iGlitch/4b73ad11e64b2127e8d9 to your computer and use it in GitHub Desktop.
Index Updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* <?php include("update.php");?>を挿入すると過去3回の履歴を表示します | |
* テーブル用HTMLは自分で作成してください | |
* パーミッションを606か666にした、空のファイル(new.txt)を作成してください | |
* new.txtにログが残ります | |
* 書き込むときは update.php?put | |
* トップページにつかってるやつです。 | |
* サイトの更新記録などにお使いください。 | |
* タグは可です。改行は<br>に自動変換されます。 | |
*/ | |
//---------設定----------- | |
$logmax = 100; //ログ記録最大行 | |
$max = 3; //表示件数 | |
$page_def= 10; //過去ログ何件ずつ | |
$logfile = "new.txt"; //ログファイル名 | |
$pwd = "0123"; //パスワード(変更してください | |
// | |
$now = gmdate("Y/m/d(D) H:i", time()+9*60*60);//日付のフォーマット | |
if(phpversion()<"4.1.0") { | |
$_SERVER = $HTTP_SERVER_VARS; | |
$_POST = $HTTP_POST_VARS; | |
} | |
$lines = file($logfile);//ファイルを配列に読み込む | |
//過去ログ表示時ヘッダです | |
if($_SERVER['QUERY_STRING']){ | |
//include("header.php"); | |
echo "<html><body>"; | |
} | |
if($_SERVER['QUERY_STRING']=="regi"){//ログ書き込み | |
if(!isset($_POST['com'])) die("何も入力されてません。"); | |
$com = $_POST['com']; | |
if(get_magic_quotes_gpc()) $com = stripslashes($com); | |
if($html) $com = htmlspecialchars($com); | |
if(!$br) $com = nl2br($com); //改行文字の前に<br>を代入する。 | |
$com = preg_replace("/[\r\n]/", "", $com); //\nを文字列から消す。 | |
$message = "<p>■ ".$now."<br> ".$com."</p>\n"; | |
$fp = fopen ($logfile , "w"); //書き込みモードでオープン | |
flock($fp ,LOCK_EX); | |
fputs ($fp, "$message"); //先頭に書き込む | |
for($i = 0; $i < $logmax; $i++) //いままでの分を追記 | |
fputs($fp, $lines[$i]); | |
fclose ($fp); | |
echo $message; | |
echo "--------更新完了------------"; | |
} | |
if($_SERVER['QUERY_STRING']=="put"){//更新書き込みフォーム | |
$pass = $_POST['pass']; | |
if(isset($pass) && $pass != $pwd) die("パスワードが違うよ"); | |
echo "<table width='100%'><tr><th bgcolor=ffd833>管理モード</font></th></tr></table>\n"; | |
if (!$pass){ | |
?> | |
<P><center><h4>パスワードを入力して下さい</h4> | |
<form action="?put" method=POST> | |
<input type=password name=pass size=8> | |
<input type=submit value=" 認証"></form></center><hr> | |
<?php | |
}else { | |
?> | |
<form action="?regi" method=POST><table width=350 align=center> | |
<tr><td align=center><h4>更新情報をいれてください。</h4></td></tr> | |
<tr><td align=left>■<?php echo $now;?></td><td> </td></tr> | |
<tr><td colspan=2><textarea name="com" cols="45" rows="5"></textarea></td></tr> | |
<tr><td> </td><td align=left><input type="checkbox" name="br" value="1">改行を<br>に変換しない<br> | |
<input type="checkbox" name="html" value="1">HTMLタグを無効にする</td></tr> | |
<tr><td colspan=2 align=right><input type=submit value=" index更新 "><input type=reset value="clear"></form></td></tr></table><hr> | |
<?php | |
} | |
} | |
if(strstr($_SERVER['QUERY_STRING'],"old")){//過去ログ表示部分 | |
echo "<hr size=1><h2>過去の更新記録</h2><br><ul>"; | |
/* 1ページずつ表示 */ | |
//?old+3を展開->$page=3 | |
$page = strstr($_SERVER['QUERY_STRING'], '+'); | |
if($page){//page=3が設定されたら開始位置は(3-1)*10=20 配列20番目 | |
$st = ($page-1) * $page_def;// | |
}else{ | |
$page = 1;//最初はpage=1 | |
} | |
for($i = $st; $i < $st+$page_def; $i++){//10件ずつ表示 | |
echo $lines[$i]; | |
} | |
if (sizeof($lines) > $page_def) {//10件より多いならページング作成 | |
$pages = ceil(sizeof($lines) / $page_def);//35÷10=3.5 ceil切り上げ 4 | |
for ($i = 1; $i <= $pages; $i++) {//ログ35行なら4ページ | |
if($page == $i){//今表示しているのはリンクしない | |
$next .= " $i "; | |
}else{ | |
$next .= " <a href=\"update.php?old+$i\">$i</a> ";//他はリンク | |
} | |
} | |
echo "<p>[ Page: $next ]";//[12 3 4] | |
} | |
echo "</ul><br><hr size=1><p align=right><a href=?put>管理</a><br>\n"; | |
}else{//実際の表示部分 | |
for($i = 0; $i < $max; $i++) | |
echo $lines[$i]; | |
echo "<div align=right><a href=\"update.php?old\">>></a></div>"; | |
} | |
if($_SERVER['QUERY_STRING']){//過去ログ表示時ヘッダー | |
echo "<hr><p align=right>- <a href=http://glitchery.jp>Index Updater</a> -"; | |
//include("foot.php"); | |
exit; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment