Aptanaを使ってPHPで掲示板アプリを作ろうとしましたが、掲示板への書き込みを行おうとすると以下のエラーが出て実現されません。
ご存知でしたらお知恵をお借りできませんか。
(line 38)Warning: array_unshift() expects parameter 1 to be array, boolean given in
<?php $save_file = dirname(__FILE__)."/bbslog.txt"; $mode = isset ($_GET["mode"]) ? $_GET["mode"] : "show"; switch ($mode) { case "show" : mode_show() ; break; case "write" : mode_write() ; break; default : mode_show() ; break; } function mode_show() { show_form(); $log = load_data(); echo "<ul>"; foreach ((array)$log as $i) { $name = htmlspecialchars($i["name"]); $body = htmlspecialchars($i["body"]); echo "<li><b style='color:red;'>$name</b>: $body</li>\n"; } echo "<ul>"; } function show_form() { echo <<< __FORM__ <form> 名前: <input type="text" name="name" size="8"/> 本文: <input type="text" name="body" size="30"/> <input type="submit" value="書く"/> <input type="hidden" name="mode" value="write"/> </form><hr/> __FORM__; } function mode_write() { if ($_GET["name"] == "" || $_GET["body"] == "") { echo "名前か本文が空です。入力してください。"; exit; } $log = load_data(); array_unshift($log, $_GET); save_data($log); $self = $_SERVER['SCRIPT_NAME']; echo "<a href='$self'>書き込みました</a>"; } function load_data() { global $save_file; $log = array(); if (file_exists($save_file)) { $txt = file_get_contents($save_file); $log = unserialize($txt); } return $log; } function save_data($log) { global $save_file; $txt = serialize($log); file_put_contents($save_file, $txt); }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/10 09:53
2016/09/10 10:05
2016/09/10 10:09