用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3907|回复: 3
收起左侧

我把session 和cookie 放到model里不行吗?

[复制链接]
发表于 2009-10-26 15:50:54 | 显示全部楼层 |阅读模式
Model
password.php

class Password extends Model{
function Password(){
  parent::Model();
  $this->load->database();
}
function ls_rand($min = NULL,$max = NULL){
  static $seeded;
  if(!isset($seeded)){
   mt_srand((double)microtime()*1000000);
   $seeded = true;
  }
  if(isset($min)&&isset($max)){
   if($min>=$max){
    return $min;
   }else{
    return mt_rand($min,$max);
   }
  }else{
   return mt_rand();
  }
}
//加密
function encrypt_password($plain){
  $password = '';
  for($i=0;$i<10;$i++){
   $password.=$this->ls_rand();
  }
  $salt = substr(md5($password),0,2);
  $password = md5($salt.$plain).':'.$salt;
  return $password;
}
//解密
function check_password($get_ps,$data_ps){
  $A_data_ps = explode(":",$data_ps);
  //echo "<BR>data ps==>".$A_data_ps;
  $A_data_ps_1 = $A_data_ps['0'];
  $A_data_ps_2 = $A_data_ps['1'];
  $check_ps = md5($A_data_ps_2.$get_ps).':'.$A_data_ps_2;
  //echo $check_ps;
  //return $check_ps;
  if($check_ps==$data_ps){
   return true;
  }else{
   return false;
  }
}
//Cookie setting
function Log_set_Cookie($log_name,$password){
  $log_name_len = strlen($log_name)+20050902;
  $name_password = convert_uuencode($log_name.$password.":".$log_name_len);
  $CA_name_password = array(
                      name=>'C_log',
                      value=>'$name_password',
                      expire=>'3600',
                      path=>'/',
  );
  set_cookie($CA_name_password);
  //return convert_uuencode($name_password);
}
//sesssion setting
function Log_set_Session($log_name,$password){
  $A_S_Log = array(
            log_name =>'$log_name',
            password =>'$password',
   );
   $this->session->set_userdata($A_S_Log);
}
//登陆验证
function login_check($login_name,$password){
  $sql = "SELECT * FROM zr_admin where log_name='$login_name'";
  //echo $sql;
  $query = @$this->db->query($sql);
  $row = @$query->row();
  $data_ps = @$row->password;
  $log_name = @$row->log_name;
  //echo "data ps ===>".$data_ps;
  if(@$this->check_password($password,$data_ps)==true){
   //session
   $this->Log_set_Session($log_name,$data_ps);
   //Cookie
   $this->Log_set_Cookie($log_name,$data_ps);
   return true;
  }else{
   return false;
  }
}
}
/*End of the file password*/
/*Loaction: ./system/application/models/password.php*/


登陆后怎么这么多错误啊?A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant log_name - assumed 'log_name'
Filename: models/password.php
Line Number: 72
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant password - assumed 'password'
Filename: models/password.php
Line Number: 73
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\zrof\system\libraries\Exceptions.php:166)
Filename: libraries/Session.php
Line Number: 662
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant name - assumed 'name'
Filename: models/password.php
Line Number: 61
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant value - assumed 'value'
Filename: models/password.php
Line Number: 62
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant expire - assumed 'expire'
Filename: models/password.php
Line Number: 63
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant path - assumed 'path'
Filename: models/password.php
Line Number: 64
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\zrof\system\libraries\Exceptions.php:166)
Filename: helpers/cookie_helper.php
Line Number: 92

是不是cookie和session不能放到model里啊?
 楼主| 发表于 2009-10-26 16:26:55 | 显示全部楼层
没人会吗?
发表于 2009-10-26 20:03:08 | 显示全部楼层
你自己看看吧,你的语法有问题,变量要加 $
 楼主| 发表于 2010-7-27 11:35:20 | 显示全部楼层
已经解决了!!

本版积分规则