<?
define('SECRET', 'j8s91slksd9ab'); // secret
define('LOG', 'data.log'); // 保存用户数据
// 生成 etag
function genEtag(){
if(!empty($_SERVER['HTTP_IF_NONE_MATCH'])){
$etag = $_SERVER['HTTP_IF_NONE_MATCH'];
}else{
$etag = substr(md5(SECRET. substr(md5($_SERVER['REMOTE_ADDR']),0,16). substr(md5($_SERVER['HTTP_USER_AGENT']),0,16)),0, 16);
}
return $etag;
}
// 显示图片
function showPic($etag){
header('content-type:image/png');
header('Etag:'.$etag);
$im = imagecreate(1, 1); // 生成1x1px的透明图片
imagecolorallocatealpha($im, 0, 0, 0, 127);
imagepng($im);
imagedestroy($im);
exit();
}
// 获取存储的数据
function getData(){
$logdata =
file_exists(LOG)?
file_get_contents(LOG) : '';
if(!$logdata){
$data = array();
}else{
$data = json_decode($logdata, true);
}
return $data;
}
$etag = genEtag();
$pic = isset($_GET['pic'])? $_GET['pic'] : 0;
if($pic==1){
showPic($etag);
}
$data = getData();
// 提交
表单
$send = isset($_POST['send'])? $_POST['send'] : 0;
if($send==1){
$txt = isset($_POST['txt'])? $_POST['txt'] : '';
if($txt!=''){
$data[$etag] = $txt;
file_put_contents(LOG, json_encode($data),true);
}
}
$txt = isset($data[$etag])? $data[$etag] : ''; // 用户输入的数据
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title> PIC ETAG - www.jb200.com</title>
</head>
<body>
<img src="pic.png">
<form method="post" action="index.php">
<p>请填写内容:</p>
<p><textarea name="txt" style="width:450px;height:150px"><?=$txt ?></textarea></p>
<p><input type="submit" value="提交"></P>
<input type="hidden" name="send" value="1">
</form>
</body>
</html>