‘DB_DSN‘ => ‘mysql://root:123456@localhost:3306/thinkphp#utf8‘
pdo
//PDO连接方式
‘DB_TYPE‘ => ‘pdo‘, // 数据库类型
‘DB_USER‘ => ‘root‘, // 用户名
‘DB_PWD‘ => ‘‘, // 密码
‘DB_PREFIX‘ => ‘think_‘, // 数据库表前缀
‘DB_DSN‘ => ‘mysql:host=localhost;dbname=thinkphp;charset=utf8‘
I(‘get.id‘,0); // 如果不存在$_GET[‘id‘] 则返回0
I(‘post.name‘,‘‘,‘htmlspecialchars‘);
// 采用htmlspecialchars方法对$_POST[‘name‘] 进行过滤,如果不存在则返回空字符串
I(‘session.user_id‘,0); // 获取$_SESSION[‘user_id‘] 如果不存在则默认为0
I(‘cookie.‘); // 获取整个 $_COOKIE 数组
I(‘server.REQUEST_METHOD‘); // 获取 $_SERVER[‘REQUEST_METHOD‘]
验证码
控制器
public function verify_c(){
$Verify = new \Think\Verify();
$Verify->fontSize = 18;
$Verify->length = 4;
$Verify->useNoise = false;
$Verify->codeSet = ‘0123456789‘;
$Verify->imageW = 130;
$Verify->imageH = 50;
//$Verify->expire = 600;
$Verify->entry();
}
试图
<p class="top15 captcha" id="captcha-container">
<input name="verify" width="50%" height="50" class="captcha-text" placeholder="验证码" type="text">
<img width="30%" class="left15" height="50" alt="验证码" src="{:U(‘Admin/Index/verify_c‘,array())}" title="点击刷新">
</p>
js代码
<script type="text/javascript" src="__ROOT__/Public/js/Admin/jq.js"></script>
<script type="text/javascript">
<!--
var captcha_img = $(‘#captcha-container‘).find(‘img‘);
var verifyimg = captcha_img.attr("src");
captcha_img.attr(‘title‘, ‘点击刷新‘);
captcha_img.click(function(){
if( verifyimg.indexOf(‘?‘)>0){
$(this).attr("src", verifyimg+‘&random=‘+Math.random());
}else{
$(this).attr("src", verifyimg.replace(/\?.*$/,‘‘)+‘?‘+Math.random());
}
});
//-->
</script>
在common目录下的function.php里加入全局函数
[php] view plaincopy在CODE上查看代码片派生到我的代码片
function check_verify($code, $id = ""){
$verify = new \Think\Verify();
return $verify->check($code, $id);
}
原文地址:http://blog.csdn.net/demon0313/article/details/45600225