Principle: Do not use Javascript,session,cookies,flash.
Using picture ETag to identify users
1. Generate a unique etag based on the user's remote_addr and http_user_agent.
2. Output the ETag to the client.
3. Get Http_if_none_match to determine whether to access the same user.
. htaccess rewrite
<ifmodule mod_rewrite.c>
rewriteengine on
rewriterule ^pic.png$ index.php?pic=1 [NC]
</ Ifmodule>
SOURCE index.php:
? Define (' SECRET ', ' j8s91slksd9ab '); Secret define (' LOG ', ' data.log ');
Save user Data//Generate ETag//More Highlights: Http://www.bianceng.cnhttp://www.bianceng.cn/web/Skills/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_agen
T ']), 0,16), 0, 16);
return $etag;
//Show Picture function Showpic ($etag) {header (' content-type:image/png ');
Header (' Etag: '. $etag); $im = Imagecreate (1, 1);
Generate 1x1px transparent picture Imagecolorallocatealpha ($im, 0, 0, 0, 127);
Imagepng ($im);
Imagedestroy ($im);
Exit ();
//Get Stored data 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 (); Submit Form $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]: '; User-entered data?> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >