Example #1
0
 static function act_message()
 {
     if (post('message_submit', 'isset')) {
         //检查验证码
         $check_code = post('code', 'post');
         if ($check_code != session('message_code', true)) {
             http::json(array('error' => 2, 'info' => 'check_code error'));
         }
         //接收、过滤数据
         $data['user_name'] = post('name', 'title');
         $data['tel'] = post('contact_tel', 'number');
         $data['phone'] = post('contact_phone', 'account');
         $data['email'] = post('email', 'account');
         $data['message'] = post('message_content', 'info');
         //验证数据
         $data['tel'] = safe::reg($data['tel'], 'tel') ? $data['tel'] : null;
         $data['phone'] = safe::reg($data['phone'], 'phone') ? $data['phone'] : null;
         $data['email'] = safe::reg($data['email'], 'email') ? $data['email'] : null;
         if ($data['message']) {
             $add_result = db::add('message', $data);
             //将数据写入留言表
             if ($add_result) {
                 http::json(array('error' => 0, 'info' => 'add message succeed'));
             }
         }
     }
     //以json格式返回给浏览器
     http::json(array('error' => 1, 'info' => 'add message failed'));
 }
Example #2
0
 static function get_qrcode($str, $w_h = '120', $level = 'L', $margin = '0')
 {
     $str = trim($str);
     $str = safe::reg($str, 'url') ? urlencode($str) : $str;
     $gg_url = 'http://chart.apis.google.com/chart?';
     $url_param = 'chs=' . $w_h . 'x' . $w_h . '&cht=qr&chld=' . $level . '|' . $margin . '&chl=' . $str;
     // return $gg_url.$url_param;
     return '<img src=' . $gg_url . $url_param . '>';
 }
Example #3
0
function url($lie = 0, $type = 0)
{
    // $lie=$lie+n; //n为相对根目录的深度
    $server_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
    $param = explode('/', trim($server_uri, '/'));
    if ($lie < count($param)) {
        $value = get_magic_quotes_gpc() ? $param[$lie] : addslashes($param[$lie]);
        if (is_int($type)) {
            return $type ? abs((int) $value) : strval(trim($value));
        }
        return safe::reg($value, $type) ? $value : null;
    }
}
Example #4
0
 static function check($value, $rule, $type = 'regex')
 {
     $type = strtolower(trim($type));
     switch ($type) {
         case 'in':
             //是否在指定范围值之内,逗号分隔字符串或者数组
         //是否在指定范围值之内,逗号分隔字符串或者数组
         case 'notin':
             $range = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'in' ? in_array($value, $range) : !in_array($value, $range);
         case 'between':
             //在某个区间内
         //在某个区间内
         case 'notbetween':
             //在某个区间外
             list($min, $max) = is_array($rule) ? $rule : explode(',', $rule);
             return $type == 'between' ? $value >= $min && $value <= $max : $value < $min || $value > $max;
         case 'equal':
             //是否相等
         //是否相等
         case 'notequal':
             //是否不等
             return $type == 'equal' ? $value == $rule : $value != $rule;
         case 'length':
             //长度
             $length = mb_strlen($value, 'utf-8');
             if (strpos($rule, ',')) {
                 //指定长度区间内
                 list($min, $max) = explode(',', $rule);
                 return $length >= $min && $length <= $max;
             } else {
                 //长度相等
                 return $length == $rule;
             }
         case 'expire':
             //有效期
             $now_time = time();
             list($start, $end) = explode(',', $rule);
             $start = is_numeric($start) ? $start : strtotime($start);
             $start = is_numeric($end) ? $end : strtotime($end);
             return $now_time >= $start && $now_time <= $end;
         case 'regex':
         default:
             //默认使用正则验证 可以使用验证类中定义的验证名称
             //检查附加规则
             return safe::reg($value, $rule);
     }
 }