public function login()
{
if ($this->check_login()) {
redirect(base_url('user/index'));
//redirect(base_url('user/apps'));
}
//redirect($this->_manager_base_url);
//處理scrf攻擊的問題。
/* $value = "aspire_DefenseSCRF";
if(!$_COOKIE['cookie_scrf']){
setcookie("cookie_scrf", $value, time()+3600);
}
$hash = md5($_COOKIE['cookie_scrf']);
*/
$hash_post = $this->input->post('hash', true);
$data = array(
'error' => '',
'fill_name' => '',
'hash' => $hash_post,
);
//解決主機頭攻擊的問題
$host = 'http://' . $_SERVER['HTTP_HOST'];
/* if ((!strpos($host, '10086dg.cn')) &&(!strpos($host, 'weili.cn')) && (!strpos($host, 'dghui.com')) && (!strpos($host, 'gitdg')) && (!strpos($host, 'cmpower.cn'))) {
$name = '';
$this->_load_login_view($data, $name, '你的請求url不合法');
return;
} */
if (!$this->input->post()) {
$token = md5(uniqid(rand(), TRUE));
$this->wlsession->set('token_login_cache', $token);
$this->wlsession->write_sid_to_cookie();
//$this->cache->save('token_login_cache', $token,1800);
//$this->cache->save('token_time', time(),1800);
$data = array(
'error' => '',
'fill_name' => '',
'hash' => $token,
);
$this->_load_login_view($data);
return;
}
// 驗證登陸
$name = strval($this->input->post('n_input', true));
$password = strval($this->input->post('p_input', true));
//處理scrf攻擊的問題。
/*if ( $hash_post != $this->wlsession->get('token_login_cache')) {
$name = '';
$token = md5(uniqid(rand(), TRUE));
$this->wlsession->set('token_login_cache', $token);
$this->wlsession->write_sid_to_cookie();
//$this->cache->save('token_login_cache', $token,1800);
//$this->cache->save('token_time', time(),1800);
$data = array(
'error' => '',
'fill_name' => '',
'hash' => $token,
);
$this->_load_login_view($data, $name, '你的請求不合法');
//.$hash_post .'!='. $this->cache->get('token_login_cache')
return;
}*/
$token_age = time() - $this->cache->get('token_time');
if ($token_age >= 300) {
//$name = '';
//$this->_load_login_view($data, $name, '你的請求時間不合法'.$this->cache->get('token_time'));
//return;
}
if (empty($name) || empty($password)) {
$name = strlen($name) == 64 ? $this->_rsa_decode($name) : $name;
$this->_load_login_view($data, $name, '用戶名或密碼不能爲空');
return;
}
if (strlen($name) != 64 || strlen($password) != 64) {
$this->_load_login_view($data, $name, '用戶名或密碼錯誤,請重試');
return;
}
// rsa 解密用戶名及密碼
$name = $this->_rsa_decode($name);
$password = $this->_rsa_decode($password);
if (!$name || !$password) {
$this->_load_login_view($data, $name, '用戶名或密碼錯誤,請重試');
return;
}
// 是否須要驗證碼?
// if ($this->_check_need_captcha($name)) {
if (false) {
$code = strval($this->input->post('code', true));
if (empty($code)) {
$this->_load_login_view($data, $name, '驗證碼不能爲空');
return;
}
$this->load->library('Captcha');
if (!$this->captcha->verify_captcha($name, $code)) {
$this->_load_login_view($data, $name, '驗證碼輸入錯誤,請從新輸入');
return;
} else {
$this->captcha->destroy_captcha($name);
}
}
$this->load->model('user_model', 'user');
$user = $this->user->get_user_by_name($name);
if (false === $user) {
$this->_raise_error_times($name);
$this->_load_login_view($data, $name, '用戶名或密碼錯誤,請重試');
return;
}
if ($user->password != md5($user->salt . $password)) {
$this->_raise_error_times($name);
$this->_load_login_view($data, $name, '用戶名或密碼錯誤,請重試');
return;
}
//檢查角色組是否處於被禁止使用狀態*************************
$row = $this->db->from("wl_auth_role_user")->where('user_id', $user->id)->get()->row();
$rolezu = $this->db->from('wl_auth_role')->where('id', $row->role_id)->get()->row();
if ($rolezu->is_del != 1) {
$this->_raise_error_times($name);
$this->_load_login_view($data, $name, '該角色組被禁用,請聯繫超級管理員解除');
return;
}
//檢查用戶是否處於被禁止使用狀態
if ($user->status != 1) {
$this->_raise_error_times($name);
$this->_load_login_view($data, $name, '該用戶被禁用,請聯繫超級管理員解除');
return;
}
//**********************************************
// 檢查是否已綁定
$this->load->model('binding_model');
$binded_wx_name = $this->binding_model->get_name_by_user_id($user->id);
// 登陸成功, 設置session
$this->user_id = $user->id;
$this->user_name = $user->login_name;
//爲了數據共用,緩存user_id都是存父帳號的
if ($user->pid == 0) {
$this->wlsession->set('user_id', $user->id);
} else {
$this->wlsession->set('user_id', $user->pid);
}
// $this->wlsession->set('sub_user_id', '');
$this->wlsession->set('auth_user_type', AUTH_USER_TYPE_USER);
$this->wlsession->set('login_name', $user->login_name);
$this->wlsession->set('wx_name', $binded_wx_name);
$this->wlsession->set('wx_qr_code', $this->binding_model->get_wx_qr_code_by_user_id($user->id));//顯示用戶二維碼圖片
$this->wlsession->write_sid_to_cookie();
//設置用戶的權限session******15-04-09 ***********************************
$this->load->model('user_model');
$this->load->model('auth_role_model');
$this->load->model('auth_node_model');
// $this->load->model('auth_role_node_model','auth_role_node_model');
// $role_name = $this->db->select("name")->from('wl_auth_role')->where('id', $row->role_id)->get()->row();
// $auth_powers = $this->auth_role_node_model->get_powers(intval($row->role_id));
// $this->wlsession->set('auth_powers', $auth_powers);//當前用戶權限存到session中
// $this->wlsession->set('user_role', $role_name->name);//所屬角色
$this->wlsession->set('user_pid', $user->pid);
//*******************************************************************
// 更新登陸信息
$last_login_date = date('Y-m-d h:i:s', time());
$update_user = array(
'login_times' => $user->login_times + 1,
'last_login_date' => $last_login_date,
'last_login_ip' => $_SERVER["REMOTE_ADDR"]
);
$this->user->update($user->id, $update_user);
echo '--hi4--';
// 重置錯誤次數控制
$this->_reset_error_times($name);
// 若是未綁定,則跳到綁定頁
if (empty($binded_wx_name)) {
redirect(base_url('bind/index'));
} else {
//redirect(base_url('user/index'));
redirect(base_url('user/apps'));
exit;
}
}
if ( ! function_exists('redirect'))
{
function redirect($uri = '', $method = 'location', $http_response_code = 302) {
if (!preg_match('#^https?://#i', $uri)) {
$uri = site_url($uri);
}
switch ($method) {
case 'refresh' :
header("Refresh:0;url=" . $uri);
break;
default :
header("Location: " . $uri, TRUE, $http_response_code);
break;
}
exit;
}
}
INFO - 2018-10-30 09:34:05 --> [async.bef.MRDSmiOb](/target/index),([])
ERROR - 2018-10-30 09:34:05 --> Severity: Notice --> Undefined index: token E:\html\pim\php_weili_activities\application\core\WL_Controller.php 35
INFO - 2018-10-30 09:34:05 --> [async.aft.MRDSmiOb] exec=0 S
ERROR - 2018-10-30 09:34:05 --> Severity: Notice --> Use of undefined constant I - assumed 'I' E:\html\pim\php_weili_activities\system\core\Hooks.php 226
INFO - 2018-10-30 09:34:16 --> [async.bef.5k9aTj6K](/user/login),([])
ERROR - 2018-10-30 09:34:16 --> Severity: Notice --> Undefined index: token E:\html\pim\php_weili_activities\application\core\WL_Controller.php 35
INFO - 2018-10-30 09:34:49 --> [async.bef.FAQ8j8DN](/user/login),([])
ERROR - 2018-10-30 09:34:49 --> Severity: Notice --> Undefined index: token E:\html\pim\php_weili_activities\application\core\WL_Controller.php 35
ERROR - 2018-10-30 09:34:49 --> Severity: Warning --> Cannot modify header information - headers already sent by (output started at E:\html\pim\php_weili_activities\application\core\WL_Controller.php:1) E:\html\pim\php_weili_activities\application\libraries\WLSession.php 60
INFO - 2018-10-30 09:34:49 --> [async.aft.FAQ8j8DN] exec=0 S
ERROR - 2018-10-30 09:34:49 --> Severity: Notice --> Use of undefined constant I - assumed 'I' E:\html\pim\php_weili_activities\system\core\Hooks.php 226
INFO - 2018-10-30 09:34:56 --> [async.bef.edqxLC3k](/user/login),([])
root@DESKTOP-I4OIMJC /cygdrive/e/html/pim/php_weili_activities
# grep -anR 'ob_start' ./
./application/controllers/dg/qrcode_extend_task.php.bak:135: ob_start();
./application/controllers/dg/scene_code_task.php.bak:145: ob_start();
./application/controllers/scene_code.php.bak:386:// ob_start();
./application/controllers/schedule/qrcode_extend_worker.php.bak:139: /*ob_start();
./application/helpers/public_function_helper.php:447: ob_start();
./application/helpers/public_function_helper.php:476: ob_start();
./application/helpers/public_function_helper.php:542: ob_start();
./application/helpers/public_function_helper.php:564: ob_start();
./static/js/ueditor/php/getRemoteImage.php:55: ob_start();
./system/core/Exceptions.php:145: ob_start();
./system/core/Exceptions.php:181: ob_start();
./system/core/Loader.php:821: ob_start();
./system/core/Output.php:379: ob_start('ob_gzhandler');
./system/helpers/url_helper.php:341: ob_start();
root@DESKTOP-I4OIMJC /cygdrive/e/html/pim/php_weili_activities
root@DESKTOP-I4OIMJC /cygdrive/e/html/pim/php_weili_activities
# php -r "phpinfo();"|grep --color 'output_buffering'
output_buffering => 0 => 0
用PHP的ob_start();
控制您的瀏覽器cachegit
Output Control 函數可讓你自由控制腳本中數據的輸出。它很是地有用,特別是對於:當你想在數據已經輸出後,再輸出文件頭的狀況。輸出控制函數不對使用 header() 或 setcookie(), 發送的文件頭信息產生影響,只對那些相似於 echo() 和 PHP 代碼的數據塊有做用。
咱們先舉一個簡單的例子,讓你們對Output Control有一個大體的印象:
Example 1.數據庫
程序代碼 程序代碼
<?php
ob_start(); //打開緩衝區
echo \"Hellon\"; //輸出
header("location:index.php"); //把瀏覽器重定向到index.php
ob_end_flush();//輸出所有內容到瀏覽器
?>瀏覽器
全部對header()函數有了解的人都知道,這個函數會發送一段文件頭給瀏覽器,可是若是在使用這個函數以前已經有了任何輸出(包括空輸 出,好比空格,回車和換行)就會提示出錯。若是咱們去掉第一行的ob_start(),再執行此程序,咱們會發現獲得了一條錯誤提示:"Header had all ready send by"!可是加上ob_start,就不會提示出錯,緣由是當打開了緩衝區,echo後面的字符不會輸出到瀏覽器,而是保留在服務器,直到你使用 flush或者ob_end_flush纔會輸出,因此並不會有任何文件頭輸出的錯誤!緩存
1、 相關函數簡介:
一、Flush:刷新緩衝區的內容,輸出。
函數格式:flush()
說明:這個函數常用,效率很高。
二、ob_start :打開輸出緩衝區
函數格式:void ob_start(void)
說明:當緩衝區激活時,全部來自PHP程序的非文件頭信息均不會發送,而是保存在內部緩衝區。爲了輸出緩衝區的內容,可使用ob_end_flush()或flush()輸出緩衝區的內容。
3 、ob_get_contents :返回內部緩衝區的內容。
使用方法:string ob_get_contents(void)
說明:這個函數會返回當前緩衝區中的內容,若是輸出緩衝區沒有激活,則返回 FALSE 。
四、ob_get_length:返回內部緩衝區的長度。
使用方法:int ob_get_length(void)
說明:這個函數會返回當前緩衝區中的長度;和ob_get_contents同樣,若是輸出緩衝區沒有激活。則返回 FALSE。
五、ob_end_flush :發送內部緩衝區的內容到瀏覽器,而且關閉輸出緩衝區。
使用方法:void ob_end_flush(void)
說明:這個函數發送輸出緩衝區的內容(若是有的話)。
六、ob_end_clean:刪除內部緩衝區的內容,而且關閉內部緩衝區
使用方法:void ob_end_clean(void)
說明:這個函數不會輸出內部緩衝區的內容而是把它刪除!
七、ob_implicit_flush:打開或關閉絕對刷新
使用方法:void ob_implicit_flush ([int flag])
說明:使用過Perl的人都知道$|=x的意義,這個字符串能夠打開/關閉緩衝區,而ob_implicit_flush函數也和那個同樣,默認爲關閉緩衝區,打開絕對輸出後,每一個腳本輸出都直接發送到瀏覽器,再也不須要調用 flush()服務器
2、深刻了解:cookie
1. 關於Flush函數:
這個函數在PHP3中就出現了,是一個效率很高的函數,他有一個很是有用的功能就是刷新browser的cache.咱們舉一個運行效果很是明顯的例子來講明flush.
Example 2.session
程序代碼 程序代碼
<?php
for($i = 1; $i <= 300; $i++ ) print(" ");
// 這一句話很是關鍵,cache的結構使得它的內容只有達到必定的大小才能從瀏覽器裏輸出
// 換言之,若是cache的內容不達到必定的大小,它是不會在程序執行完畢前輸出的。經
// 過測試,我發現這個大小的底限是256個字符長。這意味着cache之後接收的內容都會
// 源源不斷的被髮送出去。
For($j = 1; $j <= 20; $j++) {
echo $j."
";
flush(); //這一部會使cache新增的內容被擠出去,顯示到瀏覽器上
sleep(1); //讓程序"睡"一秒鐘,會讓你把效果看得更清楚
}
?>
注:若是在程序的首部加入ob_implicit_flush()打開絕對刷新,就能夠在程序中再也不使用flush(),這樣作的好處是:提升效率!
2. 關於ob系列函數:
我想先引用個人好朋友y10k的一個例子:
Example 3.
好比你用獲得服務器和客戶端的設置信息,可是這個信息會由於客戶端的不一樣而不一樣,若是想要保存phpinfo()函數的輸出怎麼辦呢?在沒有緩衝區控制以前,能夠說一點辦法也沒有,可是有了緩衝區的控制,咱們能夠輕鬆的解決:
程序代碼 程序代碼
<?php
ob_start(); //打開緩衝區
phpinfo(); //使用phpinfo函數
$info=ob_get_contents(); //獲得緩衝區的內容而且賦值給$info
$file=fopen(\'info.txt\',\'w\'); //打開文件info.txt
fwrite($file,$info); //寫入信息到info.txt
fclose($file); //關閉文件info.txt
?>
用以上的方法,就能夠把不一樣用戶的phpinfo信息保存下來,這在之前恐怕沒有辦法辦到!其實上面就是將一些"過程"轉化爲"函數"的方法!
或 許有人會問:"難道就這個樣子嗎?還有沒有其餘用途?"固然有了,好比筆者論壇的PHP 語法加亮顯示就和這個有關(PHP默認的語法加亮顯示函數會直接輸出,不能保存結果,若是在每次調用都顯示恐怕會很浪費CPU,筆者的論壇就把語法加亮函 數顯示的結果用控制緩衝區的方法保留了),你們若是感興趣的話能夠來看看
可能如今你們對ob_start()的功能有了必定的瞭解,上面的一個例子看似簡單,但實際上已經掌握了使用ob_start()的要點。
<1>.使用ob_start打開browser的cache,這樣能夠保證cache的內容在你調用flush(),ob_end_flush()(或程序執行完畢)以前不會被輸出。
<2>. 如今的你應該知道你所擁有的優點:能夠在任何輸出內容後面使用header,setcookie以及session,這是 ob_start一個很大的特色;也可使用ob_start的參數,在cache被寫入後,而後自動運行命令,好比ob_start(\ "ob_gzhandler\");而咱們最經常使用的作法是用ob_get_contents()獲得cache中的內容,而後再進行處理……
<3>.當處理完畢後,咱們可使用各類方法輸出,flush(),ob_end_flush(),以及等到程序執行完畢後的自動輸出。固然,若是你用的是ob_get_contents(),那麼就要你本身控制輸出方式了。
來,讓咱們看看能用ob系列函數作些什麼……
1、 靜態模版技術
簡介:所謂靜態模版技術就是經過某種方式,使得用戶在client端獲得的是由PHP產生的html頁面。若是這個html頁面不會再被更新,那麼 當另外的用戶再次瀏覽此頁面時,程序將不會再調用PHP以及相關的數據庫,對於某些信息量比較大的網站,例如sina,163,sohu。相似這種的技術 帶來的好處是很是巨大的。
我所知道的實現靜態輸出的有兩種辦法:
<1>.經過y10k修改的phplib的一個叫template.inc.php類實現。
<2>.使用ob系列函數實現。
對於第一種方法,由於不是這篇文章所要研究的問題,因此再也不贅述。
咱們如今來看一看第二種方法的具體實現:
Example 4.
程序代碼 程序代碼
<?php
ob_start();//打開緩衝區
?>
php頁面的所有輸出
<?
$content = ob_get_contents();//取得php頁面輸出的所有內容
$fp = fopen("output00001.html", "w"); //建立一個文件,並打開,準備寫入
fwrite($fp, $content); //把php頁面的內容所有寫入output00001.html,而後……
fclose($fp);
?>
這樣,所謂的靜態模版就很容易的被實現了……
2、 捕捉輸出
以上的Example 4.是一種最簡單的狀況,你還能夠在寫入前對$content進行操做……
你能夠設法捕捉一些關鍵字,而後去對它進行再處理,好比Example 3.所述的PHP語法高亮顯示。我的認爲,這個功能是此函數最大的精華所在,它能夠解決各類各樣的問題,但須要你有足夠的想象力……
Example 5.
程序代碼 程序代碼
<?php
Function run_code($code) {
If($code) {
ob_start();
eval($code);
$contents = ob_get_contents();
ob_end_clean();
}else {
echo "錯誤!沒有輸出";
exit();
}
return $contents;
?>
}
以上這個例子的用途不是很大,不過很典型$code的自己就是一個含有變量的輸出頁面,而這個例子用eval把$code中的變量替換,而後對輸出結果再進行輸出捕捉,再一次的進行處理……
Example 6. 加快傳輸
程序代碼 程序代碼
<?
/*
** Title.........: PHP4 HTTP Compression Speeds up the Web
** Version.......: 1.20
** Author........: catoc <catoc@163.net>
** Filename......: gzdoc.php
** Last changed..: 18/10/2000
** Requirments...: PHP4 >= 4.0.1
** PHP was configured with --with-zlib[=DIR]
** Notes.........: Dynamic Content Acceleration compresses
** the data transmission data on the fly
** code by sun jin hu (catoc) <catoc@163.net>
** Most newer browsers since 1998/1999 have
** been equipped to support the HTTP 1.1
** standard known as \"content-encoding.\"
** Essentially the browser indicates to the
** server that it can accept \"content encoding\"
** and if the server is capable it will then
** compress the data and transmit it. The
** browser decompresses it and then renders
** the page.
**
** Modified by John Lim (jlim@natsoft.com.my)** based on ideas by Sandy McArthur, Jr** Usage........:** No space before the beginning of the first \'<?\' tag.** ------------Start of file----------** |<?** | include(\'gzdoc.php\');** |? >** |<HTML>** |... the page ...** |</HTML>** |<?** | gzdocout();** |? >** -------------End of file-----------*/ob_start();ob_implicit_flush(0);function CheckCanGzip(){global $HTTP_ACCEPT_ENCODING;if (headers_sent() || connection_timeout() || connection_aborted()){return 0;}if (strpos($HTTP_ACCEPT_ENCODING, \'x-gzip\') !== false) return \"x-gzip\";if (strpos($HTTP_ACCEPT_ENCODING,\'gzip\') !== false) return \"gzip\";return 0;}/* $level = compression level 0-9, 0=none, 9=max */function GzDocOut($level=1,$debug=0){$ENCODING = CheckCanGzip();if ($ENCODING){print \"n<!-- Use compress $ENCODING -->n\";$Contents = ob_get_contents();ob_end_clean();if ($debug){$s = \"<p>Not compress length: \".strlen($Contents);$s .= \"Compressed length: \".strlen(gzcompress($Contents,$level));$Contents .= $s;}header(\"Content-Encoding: $ENCODING\");print \"x1fx8bx08x00x00x00x00x00\";$Size = strlen($Contents);$Crc = crc32($Contents);$Contents = gzcompress($Contents,$level);$Contents = substr($Contents, 0, strlen($Contents) - 4);print $Contents;print pack(\'V\',$Crc);print pack(\'V\',$Size);exit;}else{ob_end_flush();exit;}}?>