必威官网登录-betway必威官网|体育在线

热门关键词: 必威体育,betway必威官网,必威官网登录,必威app下载

获取用户IP

作者: 计算机网络  发布:2019-10-02

 代码如下

11-16  thinkcmf  

重点为one_mail函数。利用Mail_mimeDecode类从邮件中提取邮件头和邮件正文。

    public function import_users()
    {
       
        $members = $user = $user_contact = $user_ext = $user_last_active = $user_tag = array();
        $mid = 10000;
       
      
        $page_size = 3000;
        foreach(array(1,2,3,4,5) as $i)
        {
           
            //连接db
            $this->crm_db = $this->get_crm_db_handle();
            $this->db = get_db('default');
           
            $follow_table = 'follows_' . $i;
           
            $total = $this->db->count_all_results($follow_table);
            $page_total = ceil($total/$page_size);
           
            for($page = 1; $page < $page_total; $page++)
            {
                //连接db
                $this->crm_db = $this->get_crm_db_handle();
                $this->db = get_db('default');
 
                //获取会员
                $members = $this->db->select('*')
                                    ->from($follow_table)
                                    ->limit($page_size,($page-1)*$page_size)
                                    ->order_by('follow_id', 'asc')
                                    ->get()
                                    ->result_array();
               
              
                //开始导入
                foreach($members as $m)
                {
                    //导入到user表
                    if(empty($m['mid']))
                    {
                        $user = array(
                            'mid' => $mid,
                            'uid' =>$m['uid'],
                            'is_member' => 0,
                            'identify' => $m['telephone'],
                            'name' => $m['name'],
                            'nick' => $m['mark_name'],
                            'gender' => $m['sex'],
                            'update_time' => date('Y-m-d H:i:s', $m['create_time']),
                            'status' => 0
                        );
 
                        $this->crm_db->insert('user', $user);
 
                        //导入到user_contact表
                        if($m['qq'] OR $m['email'] OR $m['telephone'])
                        {
                            if($m['qq']) //2
                            {
                                $user_contact[] = array('uid'=>$m['uid'],'mid'=>$mid,'contact_id'=>2,'value'=>$m['qq']);
                            }
                            if($m['email']) //3
                            {
                                $user_contact[] =array('uid'=>$m['uid'],'mid'=>$mid,'contact_id'=>3,'value'=>$m['email']);
                            }
                            if($m['telephone']) //1
                            {
                                $user_contact[] = array('uid'=>$m['uid'],'mid'=>$mid,'contact_id'=>1,'value'=>$m['telephone']);
                            }
                            if($user_contact)
                            {
                                //$this->crm_db->insert_batch('user_contact', $user_contact);
                                foreach($user_contact as $uc)
                                {
                                    $this->crm_db->insert('user_contact', $uc);
                                }
                            }
                        }
 
                        //导入到user_ext表
                        if($m['avatar'] OR $m['city'] OR $m['province'] OR $m['country'])
                        {
                            $user_ext = array('uid'=>$m['uid'],'mid'=>$mid,'avatar'=>$m['avatar'], 'country'=>$m['country'],'province'=>$m['province'],'city'=>$m['city']);
                            $this->crm_db->insert('user_ext', $user_ext);
                        }
 
                        //导入到user_last_active表
                        if($m['last_talktime'] AND $m['talk_cnt'])
                        {
                            $user_last_active = array('uid'=>$m['uid'],'mid'=>$mid,'last_active_time'=>date('Y-m-d H:i:s',$m['last_talktime']), 'active_count'=>$m['talk_cnt']);
                            $this->crm_db->insert('user_last_active', $user_last_active);
                        }
 
                        //导入到user_tag表
                        $user_tags = $this->db->select('uid, gid as tag_id')->where(array('uid'=>$m['uid'], 'follow_id'=>$m['follow_id']))->get('fcate')->result_array();
                        if($user_tags)
                        {
                            foreach ($user_tags as $ut)
                            {
                                $ut['mid'] = $mid;
                                $this->crm_db->insert('user_tag', $ut);
                            }
                        }
 
                        //导入到platform表
                        $this->crm_db->insert('platform', array('uid'=>$m['uid'],'mid'=>$mid,'platform'=>$m['platform'],'platform_user_id'=>$m['unique'],'create_time'=>date('Y-m-d H:i:s', $m['create_time'])));
 
  www.111cn.net
                        $mid++;
                        $user = $user_contact = $user_ext = $user_last_active = $user_tag = array();
                    }
                  
                }
               
                //关闭数据库
                $this->crm_db->close();
                $this->db->close();
                usleep(100000);
            }
        }
 
    }

   核心文件结构:simplewind--model--lite--model.class.php /controller.class.php

复制代码 代码如下:

CI db会将所有的查询sql和和sql执行时间保存下来,为了debug。关键是这个$save_queries为TRUE,在config中并没有关闭开关。
再看看我上面的执行脚本,400万的数据,每条记录会执行7条sql,也就是说,如果要执行完这个脚本,2800万条sql记录会被保存在内存中,MB,10G内存都不够。
解决办法:
当你执行大数量的db操作时,记得:

   Mobile---controller:

<?php
header("content-type:text/html; charset=UTF-8");
/*
* record kid words and insert into database
* user by sending email to publication kid words
*
*/
include 'POP3.php';
include 'email_class.php';
include 'Mail_mimeDecode.php';
//include 'include/compatible.php';
include 'include/extend_common.php';
//include '../../htdocs/include/extend_common.php';
define('POST_FROM_EMAIL', 1);
define('DATABASE_CONNECTION_ERROR', 2); //数据库连接失败错误
define('EMAIL_CONNECTION_ERROR', 3); //邮箱连接失败错误
define('ACCOUNT_ERROR', 4); //邮箱的账号错误
define('SIGN_EMAIL_ERROR', 5); //邮件标记删除错误
define('DELELET_ERROR', 6); //删除邮件错误
define('INSERT_ERROR', 7); //插入数据失败错误

 代码如下

获取错误信息:$this->apiError()$this->apiSuccess()

class mail_data {

$this->db->save_queries = FALSE;

获取用户IP:get_client_ip()---model.class.php 

function mail_data() {
include 'config.php';
$mail_log = fopen("mail_log.txt", "a+");
$conn = @ mysql_connect($db_host, $db_user, $db_password);
if ($conn) {
mysql_select_db('t', $conn);
mysql_query("set names utf8");
$pop3 = new Net_POP3();
//判断连接是否成功
if ($pop3->connect($host, 110)) {
//判断登入是否成功
if ($pop3->login($user, $password) === true) {
$list = $pop3->_cmdList();
$sum = $pop3->_cmdStat();

统计条数: $count = M('Order')->where($where_s)->count();

//每次取多少邮件
$step = 2;
$r = 0;
//先对邮箱取$step邮件
for ($n = 0; $n < $sum[0]; $n += $step) {
$t = 0;
$users = array ();
$mail = array ();
$offset = ($sum[0] - $n) < $step ? $sum[0] - $n : $step;
//邮件循环
for ($i = $r; $i < $n + $offset; $i++) {

条件判断:$where_s['id'] = array('in',$ids);

//取得邮件信息
$user = $this->one_mail($i, $pop3, $list, $mail_log);
array_push($mail, $user['from_mail']);
array_push($users, $user);
$r = $i +1;
}
//取得mail用户数据
$str = $this->uesr_data($mail);
$value = array ();

 分页: $page = $this->page($count,10);

//当前邮件数组循环,当前邮件用户的email,小孩名,童言
for ($m = 0; $m < count($users); $m++) {
$num = 0;
$mn = $m + $n;
//数据处理
$post_text = $users[$m]['conntent'];
if (!empty ($post_text)) {
$post_text = do_submit_text($post_text);
$post_text = mysql_real_escape_string($post_text);
$post_link_num = parsed_text_include_links($post_text);
$text = do_submit_text($post_text);
$post_text_undo = mysql_real_escape_string($text);
$post_text = mysql_real_escape_string($post_text);
$val = array ();
$kid_num = $users[$m]['kid_nickname'];
if (is_numeric($kid_num) && intval($kid_num) <= 3 && intval($kid_num) > 0) {
$kid_num = intval($kid_num);
$val = $this->kid_data($users, $m, $kid_num, $post_text, $post_link_num, $post_text_undo);
if (isset ($val)) {
$value["$t"] = $val;
$num = 1;
$t = $t +1;
}
} else {
//数据库中的数据
for ($x = 0; $x < count($str); $x++) {
//判断是否是from_mail的小孩
$val["$x"] = $this->is_kid($users, $str, $m, $x, $post_text, $post_link_num, $post_text_undo);
if (isset ($val["$x"])) {
$value["$t"] = $val["$x"];
$num = 1;
$t = $t +1;
}
}
}

 查找: $info = M('Order')->where($where_s)->order('vip desc,createtime desc')->limit($page->firstRow.','.$page->listRows)->select();

//判断是否成功与数据库中数据匹配到
if ($num == 0) {
$val = $this->kid_data($users, $m, 1, $post_text, $post_link_num, $post_text_undo);
if (isset ($val)) {
$value["$t"] = $val;
$num = 1;
$t = $t +1;
}
}
}
}
//对一段数据操作
$valu = implode("),(", $value);
if ($valu != "") {
$err_time = $this->insert_date($valu);
$this->kid_message_count($value);
}
}
fclose($mail_log);
/*
if($pop3->disconnect()==false){
$this->_error(DELELET_ERROR);
}
*/
} else {
echo "帐号或密码错误!";
$this->_error(ACCOUNT_ERROR);
}
} else {
echo "连接失败...";
$this->_error(EMAIL_CONNECTION_ERROR);

 if ( $_GET['p']>ceil($count/10) )

}
} else {
echo "数据库连接失败...";
$this->_error(DATABASE_CONNECTION_ERROR);
}
}

        {

/*
*read the $i email message
*@access public
*@param int $i mail id
*@param object $pop3 pop3 protocol object
*@return array mail from ,header,content
*/
function one_mail($i, $pop3, $list, $mail_log) {
$stg = $pop3->getParsedHeaders($list[$i]['msg_id']);
$from = imap_mime_header_decode($stg['From']); //邮件的发送者
$string_from = '';
for ($j = 0; $j < count($from); $j++) {
$string_from = "$string_from" . $from[$j]->text;
}
preg_match("/([a-z0-9A-Z_]+)@([a-z0-9A-Z/.]+).([a-z0-9A-Z]+)/", $string_from, $from_mail);

         $this->apiError( 'over' );

$string = $pop3->getMsg($list[$i]['msg_id']);
$body = new Mail_mimeDecode($string);

        }else{

$sr = $body->decode(array (
'include_bodies' => true,
'decode_bodies' => false,
'decode_headers' => true
));

         $this->apiSuccess( '获取成功',array('info'=>$info) );

if (property_exists($sr, 'parts')) {
$mail_part = $sr->parts;
$mail_part = $mail_part[0];
} else {
$mail_part = $sr;
}

        }

$mail_code = $mail_part->headers;
$mail_code = $mail_code['content-transfer-encoding']; //编码格式
$mail_type = $mail_part->ctype_parameters;
$mail_type = $mail_type['charset'];
$mail_body = $mail_part->body; //正文内容

查找:$data = array( 'uid'=>$this->user['id'],'orderid'=>$_POST['id'] );

if ($mail_code == "base64") { //判断编码格式
$text = base64_decode("$mail_body");
$text = iconv("$mail_type", "UTF-8", $text);
} else {
$text = quoted_printable_decode("$mail_body");
$text = iconv("$mail_type", "UTF-8", $text);
}

       $info = M('grab_order')->where($data)->find();

$mail_title = $sr->headers;
$mail_title = $mail_title['subject'];
$mail_title = imap_mime_header_decode($mail_title);

$vo['grab_user_nicename'] =M('users')->where(array('id'=>$grab['uid']))->field('user_nicename')->find();

if (count($mail_title) != 0) {

查找: $user_login = M('users')->where("id=".$order['userid'])->getField('user_login');

$title = $mail_title[0]->text;
$t = $mail_title[0]->charset;

添加: $data['time'] = NOW_TIME;   $res = M('grab_order')->add($data);

if ($t != "default") {
$title = iconv($t, "UTF-8", $title);
} else {
$title = iconv("gb2312", "UTF-8", $title);
}
} else {
$title = 1;
}
//$pop3->_cmdDele($list[$i]['msg_id']);
$pop3->deleteMsg($list[$i]['msg_id']);
if ($pop3->deleteMsg($list[$i]['msg_id']) == false) {
$this->_error(SIGN_EMAIL_ERROR);
}
//取得需要插入的用户email,小孩名,童言
$users["$i"] = array (
"from_mail" => "$from_mail[0]",
"kid_nickname" => "$title",
"conntent" => "$text",
"body_type" => "$mail_type"
);
$log = $users["$i"];
array_unshift($log, date("Y-m-d H:i;s"));
$log = serialize($log);
fwrite($mail_log, $log . "/r/n");
return $users["$i"];
}

保存: $rel = M('order')->where($where)->save($data);

/**
*at database search $mail user's information
*@access public
*@param string $mail all email
*@return array mail user's information
*/
function uesr_data($mail) {
$mails = implode("','", $mail);
$sql = "SELECT a.mail,a.user_name,a.user_nickname,b.kid_id, b.kid_name,b.kid_avatar ,b.kid_birthday
FROM `t_users` a, `t_users_kid` b
WHERE a.mail in ('$mails') AND a.user_id=b.user_id";
$query = mysql_query($sql) or die(mysql_error());
$str1 = array ();

更改设置: M('order')->where(array('id'=>$_POST['id']))->setField('status',1);

while ($arr = mysql_fetch_array($query)) {
array_push($str1, $arr);
}
return $str1;
}
/*
*insert $value into database
*@access public
*@param string $value kid information
*@return void
*/
function insert_date($value) {
$sql_insert = "INSERT INTO `t_posts`(kid_id,user_name,user_nickname,post_time,post_text,user_avatar,post_link_num,post_text_undo,post_from,add_time)
VALUES ($value)";
$num = mysql_query($sql_insert) or die(mysql_error());

图片地址: $vo['avatar'] = "];

if ($num != 1) {
$this->_error(INSERT_ERROR);
}
}
/*
*send email to $smtpemailto
*@access public
*@param string $mailtype mail_from type
*@param string $smtpemailto mail_from
*@param string $user_kid_name mail title
*@return void
*/
function reply_email($mailtype, $smtpemailto, $user_kid_nickname) {
require "config.php";
$mailsubject = "您暂时还没有" . $user_kid_nickname . "宝宝";
$mailsubject = "=?UTF-8?B?" . base64_encode($mailsubject) . "?=";
$mailbody = "请先添加宝宝";

推送消息: $user_login = M('users')->where("id=".$order['userid'])->getField('user_login');

if ($mailtype != "ISO-8859-1") {
$mailbody = iconv("utf-8", "$mailtype//ignore", $mailbody);
}

  $mes = array( 'orderid'=>$_POST['id'],'msg'=>'您派发的订单已被抢,快去看看吧','type'=>2); if( (int)$this->pushcontent_test($user_login) ){

$mail_type = "HTML";
$smtp = new smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
$smtp->debug = FALSE;
$send_mail = $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mail_type, "", "");

    $re = pushcontent( 0,$user_login,$mes,array(),2 );}

if ($send_mail == false) {
return "send faile";
$send_mail = $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mail_type, "", "");
}
}
/*
*the kid's age then publication kid words
*@access public
*@param int $kid_birthday kid birthday
*@return array kid year month day
*/

写入数据过滤:filter()  $this->data($data)->filter('strip_tags')->add();

function get_kid_age_info($kid_birthday) {
$cur_date = date("Ymd");
$age = $cur_date - $kid_birthday;
if ($age < 0) {
return false;
}
$years = 0;
$months = 0;
$days = 0;
if ($age > 10000) {
$years = floor($age / 10000);
}

I方法:I('变量类型.变量名',['默认值'],['过滤方法'])变量类型是指请求方式或者输入类型,   

$age = $age % 10000;
$months = floor($age / 100);
if ($months > 12)
$months -= 88;
$days = $age % 100;
if ($days > $cur_date % 100) {
$days = $days - (100 - date("d", strtotime(date("Ym") . "01") - 24 * 3600));
}
return array (
$years,
$months,
$days
);
}
/**
*judge the $m message and the $x data
*@access public
*@param array $users mail information
*@param array $str user information
*@param int $m $users grade
*@param int $x $str grade
*@param string $post_text the mail text
*@return string information
*/
function is_kid($users, $str, $m, $x, $post_text, $post_link_num, $post_text_undo) {

       意为{input}是避免输入数据出现安全隐患的重要手段,I函数默认的过滤方法是

if ($users[$m]['from_mail'] == $str[$x]['mail']) { //判断是否是from_mail的小孩

        Htmlspecialchars strip_tags interval

$kid_id = $str[$x]['kid_id'];
$user_name = $str[$x]['user_name'];
$user_nickname = $str[$x]['user_nickname'];
$kid_diff = $str[$x]['kid_birthday'];
$kid_name = $str[$x]['kid_name'];
$kid_diff = date("Ymd", $kid_diff);
$kid_birthdy = $this->get_kid_age_info($kid_diff);
//格式转换
for ($j = 0; $j < count($kid_birthdy); $j++) {
if ($kid_birthdy[$j] >= 0 && $kid_birthdy[$j] < 10) {
$kid_birthdy[$j] = "0" . "$kid_birthdy[$j]";
}
}
$post_time = $kid_birthdy[0] . $kid_birthdy[1] . $kid_birthdy[2];
$user_avatar = get_kid_avatar($user_name, $kid_id);
$kid_avatar = $user_avatar;
if ($users[$m]['kid_nickname'] == $kid_name) {
$kid_id = mysql_real_escape_string("$kid_id");
$user_name = mysql_real_escape_string("$user_name");
$post_time = mysql_real_escape_string("$post_time");
$kid_avatar = mysql_real_escape_string("$kid_avatar");
$from = POST_FROM_EMAIL;
$add_time = time();
$values = "'$kid_id','$user_name','$user_nickname','$post_time','$post_text','$kid_avatar','$post_link_num','$post_text_undo','$from','$add_time'";
return $values;
}
}
}
/**
*have the kid_num kid of users information
*@access public
*@param array $users the array() of users
*@param int $m the m items of array
*@param int $kid_num the kid_num kid
*@return array kid information
*/
function user_kid($users, $m, $kid_num) {
$m_mail = $users["$m"]['from_mail'];
$sql = "SELECT a.user_name,a.user_nickname,b.kid_id, b.kid_name,b.kid_avatar ,b.kid_birthday
FROM `t_users` a, `t_users_kid` b
WHERE a.mail='$m_mail' AND a.user_id=b.user_id ORDER BY b.kid_birthday ASC ";
$query = mysql_query($sql) or die(mysql_error());
$str1 = array ();
$kids = array ();
$i = 0;
while ($arr = mysql_fetch_betway必威官网,array($query)) {
$str1[$i] = $arr;
$i = $i +1;
}
$kid_num = $kid_num -1;
if ($kid_num > (count($str1) - 1)) {
return $num = 0;
} else {
return $str1["$kid_num"];
}

get    获取GET参数               post    获取POST参数    

}
/**
*get the kid_num kid information
*@access public
*@param array $users the array() of users
*@param int $m the m items of array
*@param int $kid_num the kid_num kid
*@param string $post_text the message of mail
*@param int $post_link_num count(link) of message body
*@return array $values the kid information
*/
function kid_data($users, $m, $kid_num, $post_text, $post_link_num, $post_text_undo) {
$use_kid = $this->user_kid($users, $m, $kid_num);

request    获取REQUEST 参数      put    获取PUT 参数    

if ($use_kid != 0) {
$kid_id = $use_kid['kid_id'];
$user_name = $use_kid['user_name'];
$user_nickname = $use_kid['user_nickname'];
$kid_diff = $use_kid['kid_birthday'];
$kid_diff = date("Ymd", $kid_diff);
$kid_birthdy = $this->get_kid_age_info($kid_diff);
//格式转换
for ($j = 0; $j < count($kid_birthdy); $j++) {
if ($kid_birthdy[$j] >= 0 && $kid_birthdy[$j] < 10) {
$kid_birthdy[$j] = "0" . "$kid_birthdy[$j]";
}
}
$post_time = $kid_birthdy[0] . $kid_birthdy[1] . $kid_birthdy[2];

session    获取 $_SESSION 参数    cookie    获取 $_COOKIE 参数    

$user_avatar = get_kid_avatar($user_name, $kid_id);
$kid_avatar = $user_avatar;
$add_time = time();
$from = POST_FROM_EMAIL;
$values = "'$kid_id','$user_name','$user_nickname','$post_time','$post_text','$kid_avatar','$post_link_num','$post_text_undo','$from','$add_time'";
return $values;
}
}
/**
*update data when have kid words
*@access public
*@param array $value the array() of users
*@return void
*/
function kid_message_count($value) {
$use_names = array ();

server    获取 $_SERVER 参数      globals    获取 $GLOBALS参数 

for ($k = 0; $k < count($value); $k++) {
$k_name = explode(",", $value[$k]);
$use_names[$k] = $k_name[1];
}
asort($use_names);
$sum_kid = count($use_names);
$s = 0;
if (count($use_names) == 1) {
$d_users[0] = $use_names[0];
} else {

param    自动判断请求类型获取GET、POST或者PUT参数 param类型变量还可以用数字索引的方式获取URL参数(必须是PATHINFO模式参数有效,无论是GET还是POST方式都有效) 

//第一个
if ($use_names[0] != $use_names[1]) {
$d_users[0] = $use_names[0];
} else {
$s_users[$s] = $use_names[0];
$s = $s +1;
}
//最后一个
if ($use_names[$sum_kid -1] != $use_names[$sum_kid -2]) {
$d_users[$sum_kid -1] = $use_names[$sum_kid -1];
} else {
$s_users[$s] = $use_names[$sum_kid -1];
$s = $s +1;
}

注意:变量类型不区分大小写。变量名严格区分大小写。默认值和过滤方法均属于可选参数。

for ($k = 1; $k < count($use_names) - 1; $k++) {

echo I('get.name');// 相当于 $_GET['name']

if ($use_names[$k] == $use_names[$k -1] || $use_names[$k] == $use_names[$k +1]) {
$s_users[$s] = $use_names[$k];
$s = $s +1;
} else {
$d_users[$k] = $use_names[$k];
}

I('session.user_id',0);// 获取$_SESSION['user_id'] 如果不存在则默认为0

}
}

echo I('get.name','','htmlspecialchars');// 采用htmlspecialchars方法对$_GET['name'] 进行过滤,如果不存在则返回空字符串

if (isset ($d_users)) {
$names = implode(",", $d_users);
$sql = "UPDATE `t_users` set post_num = post_num+1 WHERE `t_users`.user_name in ($names)";
$query = mysql_query($sql) or die(mysql_error());
}

 

if (isset ($s_users)) {

echo I('param.1');// 输出2013   

for ($s = 0; $s < count($s_users); $s++) {
$name = $s_users[$s];
$sql = "UPDATE `t_users` set post_num = post_num+1 WHERE `t_users`.user_name = $name";
$query = mysql_query($sql) or die(mysql_error());
}

param变量类型的写法可简化:I('id');// 同I('param.id')I('name');// I('param.name')

}

Thinkphp3.2添加了一个I方法,取义Input,用来获取前台提交过来的数据。
I方法是放在了/ThinkPHP/Common/function.php之中

}
/**
* point error
*@access private
*@param int error_num the error code
*@return void
*
*/
private function _error($error_num) {
$error_log = fopen("error_log.txt", "a+");
switch ($error_num) {
case 2 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tCould not connect database!/r/n");
break;
case 3 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tConnection Failure!/r/n");
break;
case 4 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tAccount number or password error!!/r/n");
break;
case 5 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tsign email failed!/r/n");
break;
case 6 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tdelete emails failed!/r/n");
break;
case 7 :
fwrite($error_log, date("Y-m-d H:i:s") . "/t" . $error_num . "/tinsert data failed!/r/n");
break;
}
fclose($error_log);
}
}
?>

C()方法:C方法是ThinkPHP用于设置、获取,以及保存配置参数的方法,使用频率较高。

您可能感兴趣的文章:

  • 用PHP读取IMAP邮件
  • redhat下apache+php+mysql+imap+ldap+jdk+tomcat的安装
  • 使用PHPMailer实现邮件发送代码分享
  • php实现的发送带附件邮件类实例
  • PHP+Ajax检测用户名或邮件注册时是否已经存在实例教程
  • php使用smtp发送支持附件的邮件示例
  • php 邮件发送问题解决
  • php 发送带附件邮件示例
  • php 检查电子邮件函数(自写)
  • php实现统计邮件大小的方法
  • PHP基于imap获取邮件实例

     设置参数 

C('DB_NAME','thinkphp');

表示设置DB_NAME配置参数的值为thinkphp,由于配置参数不区分大小写

$config['user_id'] = 1;   $config['user_type'] = 1;   C($config);

如果C方法的第一个参数传入数组,就表示批量赋值,上面的赋值相当于:

C('USER_ID',1);    C('USER_TYPE',1);

获取参数   要获取设置的参数,可以用:

$userId = C('USER_ID');    $userType = C('USER_TYPE');

如USER_ID参数尚未定义过,则返回NULL。如传入的配置参数为空,表示获取全部的参数:

$config = C();

保存设置 
3.1版本增加了一个永久保存设置参数的功能,仅针对批量赋值的情况,例如:

$config['user_id'] = 1;    $config['user_type'] = 1;    C($config,'name');

在批量设置了config参数后,会连同当前所有的配置参数保存到缓存文件(或者其他配置的缓存方式)。保存之后,如果要取回保存的参数,可以用

$config = C('','name');

其中name就是前面保存参数时用的缓存的标识,必须一致才能正确取回保存的参数。取回的参数会和当前的配置参数合并,无需手动合并

惯例配置文件:simplewind--core---conf---convention。Php

require SPAPP_PATH.'Core/ThinkPHP.php';//载入框架核心文件

R()方法在其他控制器里面调用这个操作方法(一般R方法用于跨模块调用是A()升级)

R('[项目://][分组/]模块/操作','参数','控制器层名称') 

R('Admin/User/detail',array('5'));

表示调用Admin分组下面的User控制器的detail方法。

R('Admin://User/detail',array('5'));

表示调用Admin项目下面的User控制器的detail方法。

官方建议不要在同一层多太多调用,会引起逻辑的混乱,被公共调用的部分应该封装成单独的接口,可以借助3.1的新特性多层控制器,单独添加一个控制器层用于接口调用,例如,我们增加一个Api控制器层,

class UserApi extends Action {   public function detail($id){       return M('User')->find($id);   }  }

然后,使用R方法调用。也就是说,R方法的第三个参数支持指定调用的控制器层。

$data = R('User/detail',array('5'),'Api');

别名定义:application-common-conf-alias.php   "Dir" => SPAPP_PATH.'Lib/Util/Dir.class.php',

文件加载:导入文件,一般来说lib目录下的文件可以实现自动加载,

方法一:impor (‘ page ’) ;   $obj = new page(); 

 

方法二:import("ORG.ThinkSDK.ThinkOauth");$qq = ThinkOauth::getInstance('qq', $token);也可以直接实例化:$htt = new OrgNetHttp(); 

方法三:  import("Org.Net.Http",dirname(__FILE__),".class.php");

            $htt = new Http();  //反斜线代表跳出当前命名空间

            $htt::download($file_path,$file_name);

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

registerController.class.php:

获取验证码: getMsgcode()

       $map['time'] = array( 'lt',$time - 300 );

        M('msgcode')->where($map)->delete();

        $where['tel'] = $_POST['tel'];

        $info = M('msgcode')->where($where)->find();

注册:doregister()

$data['user_login'] = $_POST['tel'];

        $data['create_time'] = date( 'Y-m-d H:i:s',$time );

        $data['user_status'] = 1;

        $data['user_type'] = 2;

本文由betway必威官网发布于计算机网络,转载请注明出处:获取用户IP

关键词: