<?php $magic_a = "www.111cn.net34589"; $magic_b = "234566***+"; function getpincookie($pin_code) { global $magic_a; global $magic_b; $now = time(); $client_ip = $_server['remote_addr']; $pin = md5($now . $client_ip . $magic_a . $pin_code . $maigc_b) . $now; return $pin; } function checkpincookie($pin_code_in, $timeout=300) // 5 miniuteswww.111cn.net { global $magic_a; global $magic_b; $pin = substr($_cookie['pin'], 0, 32); $time = substr($_cookie['pin'], 32); $now = time(); if ($now - $time > $timeout) { return -100; // time_out } $pin_code_in = strtolower($pin_code_in); $client_ip = $_server['remote_addr']; $pin_2 = md5($time . $client_ip . $magic_a . $pin_code_in . $maigc_b); if ($pin === $pin_2) { return 0; } else { return -200; // pincode is error. } } function getpinimg() { // $rnd = rand(0, 10); $rnd = 0; $path = "./www.111cn.net/" . substr("00000$rnd", -4); for ($i = 0; $i < 4; ++$i) { if (__getpinimg($path)) { break; } } exit; } function __getpinimg($path) { require("$path/pinmap.php"); $pinv = $pin[rand(0, $pin_max)]; list ($file, $pin_code) = explode('#', $pinv); $filepath = "$path/$file$pin_ext"; // output pincode image. $fh = fopen($filepath, "rb"); if (!$fh) { return false; } $data = fread($fh, 10240); // php just read max size: 8k. fclose($fh); if (strlen($data) < 200) { return false; } // set cookie; header("content-type: image/jpeg"); $pin_code = strtolower($pin_code); $pin = getpincookie($pin_code); setcookie("pin", $pin); echo $data; return true; } |