How to use picture ETag to judge users

Source: Internet
Author: User
Tags define header md5

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" > 

  
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.