<?php

		function check_login(){
	    if (isset($_SESSION["userid"])) {
	        return true;
	    } else {
	    	echo "<script type='text/javascript'> window.location='".U('Index/reg')."'</script>";
        	exit;
	    }
	}

	function check_user_login(){
	    if (isset($_SESSION["userid"])) {
	        return true;
	    } else {
	    	return false;
	    }
	}

	function noncestr($num='6'){
		$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
        $noncestr = '';
        for($i =0;$i<$num;$i++) {
            $noncestr.= $chars[mt_rand(0,strlen($chars)-1)];
        }
        return $noncestr;
	}
	

	function showweek(){
		$weekarray=array("日","一","二","三","四","五","六"); //星期几
		return "周".$weekarray[date("w")];
	}

    //检查验证码是否正确
	function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}

	function echotext($str,$start=0,$length){
		$text=preg_replace('/<[^>]+>/','',$str);//去掉HTML所有的标签
		echo mb_substr(trim($text), $start, $length, 'utf-8');
	}

	function msubstr($str,$start=0,$length,$suffix=false,$charset="utf-8"){
		$strlen = mb_strlen($str,'UTF8');
		if($strlen<=$length){
			return $str;
		}else{
			$str = mb_substr($str, $start, $length,$charset);
			if($suffix===true){
				$str = $str."···";
			}
			return $str; 
		}	
	}

	function get_webconfig($name){
		//第三方对接码根据给定的key查value
		$list=M('Outh_config')->where(array('name' =>$name ))->find();
		return $list['value'];
	}