这个就是删除注释后的了~~!
- <?php
- $secnum['num_list'] = "1~1,2~2,3~3,4~4,5~5,6~6,7~7,8~8,9~9,10~10";
- $secnum['hashname'] = 'kengni';
- $secnum['fieldname_useranswer'] = "$mcspvalue";
- $secnum['fieldname_mathresult'] = "$mcspinfo";
- function math_comment_spam_protection() {
- global $secnum;
- // Get numbers in array
- $num_array = mcsp_aux_numbers_to_array($secnum['num_list']);
- // Get random keys
- $rand_keys = array_rand($num_array, 2);
- // Operands for displaying...
- $mcsp_info['operand1'] = $num_array[$rand_keys[0]];
- $mcsp_info['operand2'] = $num_array[$rand_keys[1]];
- // Calculate result
- $result = $rand_keys[0] + $rand_keys[1];
- $mcsp_info['result'] = mcsp_aux_generate_hash($result, date(j));
- return $mcsp_info;
- }
- function mcsp_check_input($answer,$result) {
- global $secnum;
- // Get result
- $value_result = $result;
- // Get value user has entered
- $value_entered = preg_replace('/[^0-9]/','',$answer); // Remove everything except numbers
- if ($value_entered == '') {
- // Case 1: User has not entered an answer at all:
- $checkresult='no_answer';
- } elseif ( $value_result != mcsp_aux_generate_hash($value_entered, date(j)) ) {
- if ( ( date('G') <= 1 ) AND ( $value_result == mcsp_aux_generate_hash($value_entered, (intval(date(j))-1) ) ) ) {
- // User has just passed midnight while writing the comment. We consider
- // the time between 0:00 and 1:59 still as the day before to avoid
- // error messages if user visited page on 23:50 but pressed the "Submit Comment"
- // button on 0:15.
- } else {
- // Case 2: User has entered a wrong answer:
- $checkresult='wrong_answer';
- }
- }
- return $checkresult;
- }
- function mcsp_aux_generate_hash($inputstring, $day) {
- global $secnum;
- // Add IP address:
- // [ not use for now... if users using dial-up connections, disconnect when writing
- // the comment and re-connect again, they will get a new IP address. ]
- // $inputstring .= getenv('REMOTE_ADDR');
- // Add name of the weblog:
- $inputstring .= $secnum['hashname'];
- // Add date:
- $inputstring .= $day . date('ny');
- // Get MD5 and reverse it
- $enc = strrev(md5($inputstring));
- // Get only a few chars out of the string
- $enc = substr($enc, 26, 1) . substr($enc, 10, 1) . substr($enc, 23, 1) . substr($enc, 3, 1) . substr($enc, 19, 1);
- // Return result
- return $enc;
- }
- function mcsp_aux_numbers_to_array($input) {
- // Converts the input string, e.g. "1~one, 2~two, 3~three, 4~four, ..."
- // into an array, e.g.: Array([1] => one, [2] => two, [3] => three, ...)
- $input = str_replace(' ', '', $input); // Strip whitespace
- $sourcearray = explode(',', $input); // Create array
- foreach ($sourcearray as $loopval) {
- $temparr = explode('~', $loopval);
- $targetarray[$temparr[0]] = $temparr[1];
- }
- return $targetarray;
- }
- function mcsp_aux_fieldname_formatting($input) {
- // Clean the input values for the field names...
- $return = preg_replace('/[^a-zA-Z0-9_\-]/', '', $input);
- return $return;
- }
- ?>
复制代码 |