Created
August 24, 2013 13:50
-
-
Save n0bisuke/6328243 to your computer and use it in GitHub Desktop.
プレドラ
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 | |
define("URL", "http://rsk-mac.local:8888/practice/chat.php"); | |
define("TIME", time()); | |
define("__THIS_FILE__", file_get_contents(__FILE__)); | |
define("__THIS_SCRIPT__", substr(__THIS_FILE__, 0, strpos(__THIS_FILE__, "__" . "halt_compiler();") + 19)); | |
$logs = explode("\n", substr(__THIS_FILE__, strpos(__THIS_FILE__, "__" . "halt_compiler();") + 19)); | |
if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0) { | |
if (isset($_POST['text']) && !empty($_POST['text']) | |
&& isset($_POST['name']) && !empty($_POST['name'])) { | |
setcookie('name', $_POST['name']); | |
$logs_original = (count($logs) > 50) ? array_slice($logs, count($logs) - 50) : $logs; | |
if (!file_put_contents(__FILE__, __THIS_SCRIPT__ . join("\n", $logs_original) | |
. str_replace(array("\t", "\n", "\r"), "", $_POST['name']) . "\t" . str_replace(array("\t", "\n", "\r"), "", $_POST['text']) . "\t" . TIME . "\n", LOCK_EX)) { | |
echo "failed to write / please set permission 666 this file.<br>"; | |
exit; | |
} | |
} | |
header("Location: " . URL); | |
} | |
else { | |
$name = isset($_COOKIE['name']) ? $_COOKIE['name'] : ""; | |
?> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<title>php simple chat</title> | |
<style type="text/css">body {font-size: 18px;font-family: "メイリオ";background:#0f0f0f;color:#ccc;} a {color:#fff;} h2 {color: #fcc;} strong {color:#99c;}</style> | |
<script laguage="JavaScript"> | |
<!-- | |
function changeImg(){ | |
location.reload(); | |
} | |
// --> | |
</script> | |
</head> | |
<body onload="document.getElementById('text-message').focus(); setInterval('changeImg()',1000*10*1); "> | |
<h1>php simple chat</h1> | |
<form method="post"> | |
name : <input type="text" size="10" name="name" value="<?php echo htmlspecialchars($name, ENT_QUOTES); ?>"><br> | |
message : <input type="text" size="50" name="text" value="" id="text-message"> <input type="submit" value="Send / Reload"><br> | |
</form> | |
<h2>chat log</h2> | |
<div style="color: #ccc";> | |
<?php foreach (array_reverse($logs) as $m) { | |
if (!empty($m)) { | |
list($log_name, $log_message, $log_date) = explode("\t", $m); | |
echo '<strong>' . htmlspecialchars($log_name, ENT_QUOTES) . "</strong> said : " . htmlspecialchars($log_message, ENT_QUOTES) . " <em> -- " . date("Y-m-d H:i:s", $log_date) ." </em><br>\n"; | |
} | |
} | |
?> | |
</div> | |
<div style="border-top: solid 5px #fff; margin-top: 10px; padding-top: 10px;">"<a href="http://gist.github.com/33390">php simple chat</a>" powered by <a href="http://d.hatena.ne.jp/sotarok/">sotarok</a> with <a href="http://nequal.jp">nequal</a></div> | |
</body> | |
</html> | |
<?php | |
} | |
exit; | |
__halt_compiler();hoge ほげほげ 1377351641 | |
n0bisuke ほげほげ 1377351867 | |
n0bisuke ああああ 1377351871 | |
n0bisuke ほげほげ 1377351879 | |
karube nice 1377351963 | |
のびすけ ほげほげ 1377351967 | |
のびすけ ふがふが 1377351985 | |
さわみん 眠くなってきました。 1377351991 | |
なかぞの うわー 1377352228 | |
なかぞの え? 1377352242 | |
のびすけ え? 1377352269 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment