問題
這個問題是因為在 ubuntu 不知道哪一版開始,預設會把 php 刪除 session 的動作關掉
然後系統會自行使用 /usr/lib/php/sessionclear 的命令來清除 session
但預設刪除的是 sess_* 的檔案
但 CodeIgniter 3 產生的 session 檔案為 ci_session* 的檔案
目前分類:PHP (50)
- Nov 06 Mon 2017 17:50
[PHP] Ubuntu 下使用 CodeIgniter 3 ,session 無法自動被刪除的問題
- Oct 02 Mon 2017 18:02
[PHP] 正規表示法拆成多行以及加註解的寫法
第一次看到,快速做個筆記。
function isMatch($url) { $rx = '~ ^([a-z]+) # 註解1 ([0-9]+)$ # 註解2 ~x'; return preg_match($rx, $url); } isMatch("111222333"); // false isMatch("aaabbccc"); // false isMatch("a1"); // true isMatch("abc123"); // true
- Sep 06 Tue 2016 22:33
[PHP] Linux Command Line 進度Bar (多行版本)
最近經常在寫 Command Line 命令來做資料庫資料的轉換
所以想要弄個進度Bar 來做簡單的時間預估,但沒特殊處理就是一直 echo 很醜
稍微 Google 了一下發現不難處理,以下簡單筆記一下
要做進度 Bar ,就是要把訊息畫在畫面上相同的地方
- Mar 24 Thu 2016 10:44
[PHP] Laravel 自行新增設定檔案及存取方法
這個部份我找了好久,官網也沒有寫,但後來自己試出來了,以下是筆記:
新增設定檔
直接在 /config/ 底下隨便複製一個檔案,然後把裡面內容改成自己要的
如:my.php
- Mar 22 Tue 2016 17:09
[PHP] 使用 ajax post 上傳檔案
參考文章: http://abandon.ie/notebook/simple-file-uploads-using-jquery-ajax
測試程式碼:
<?php // ajax 呼叫 if (isset($_POST['upload_form'])) { echo "<pre>_FILES = " . print_r($_FILES, TRUE). "</pre>"; } // 一般 form submit elseif (isset($_FILES) && $_FILES) { echo json_encode($_FILES); return; } ?> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <script src="https://code.jquery.com/jquery-1.12.2.js"></script> <script> var ajax_upload = { files : [], init : function () { var _self = this; // 綁定檔案變更時的處理 $('input[type=file]').on('change', function(event) {_self.prepareUpload(event); }); // 上傳 $('#upload_ajax').bind('click', function (event) { _self.upload(event); }); }, prepareUpload : function (event) { this.files = event.target.files; console.log(this.files); }, upload : function () { console.log('files = ', this.files); var data = new FormData(); $.each(this.files, function(key, value) { data.append(key, value); }); $.ajax( { url : 'ajax_post_file.php', type : 'POST', data : data, cache : false, dataType : 'json', processData : false, contentType : false, success: function(data, textStatus, jqXHR) { console.log('upload success!!'); }, error: function(jqXHR, textStatus, errorThrown) { console.log('ERRORS: ' + textStatus); } }); } }; $(function() { ajax_upload.init(); }); </script> <form method="post" enctype="multipart/form-data"> <input type="file" name='photo' id='photo'> <button id='upload_form' name='upload_form' type='submit'>form 上傳</button> <button id='upload_ajax' name='upload_ajax' type='button'>ajax 上傳</button> </form>
- Dec 17 Thu 2015 15:46
[PHP] Mac 上安裝 xdebug
步驟
1. 安裝 xdebug
# brew install php55-xdebug
2. 編輯 php.ini
- Dec 15 Tue 2015 10:33
[PHP] 設定顯示 PHP 的錯誤訊息
錯誤訊息無法顯示時,請照以下步驟檢查
1. 檢查 php.ini
display_errors = On
error_reporting = E_ALL
- Dec 02 Wed 2015 10:58
[PHP] CodeIgniter 的環境切換,設定 $_SERVER['CI_ENV']
在 CodeIgniter 的 index.php 中有這樣一段程式
/* *--------------------------------------------------------------- * APPLICATION ENVIRONMENT *--------------------------------------------------------------- * * You can load different configurations depending on your * current environment. Setting the environment also influences * things like logging and error reporting. * * This can be set to anything, but default usage is: * * development * testing * production * * NOTE: If you change these, also change the error_reporting() code below */ define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development'); /* *--------------------------------------------------------------- * ERROR REPORTING *--------------------------------------------------------------- * * Different environments will require different levels of error reporting. * By default development will show errors but testing and live will hide them. */ switch (ENVIRONMENT) { case 'development': error_reporting(-1); ini_set('display_errors', 1); break; case 'testing': case 'production': ini_set('display_errors', 0); if (version_compare(PHP_VERSION, '5.3', '>=')) { error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); } else { error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); } break; default: header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'The application environment is not set correctly.'; exit(1); // EXIT_ERROR }
這裡可以看到 ENVIRONMENT 的值是由 $_SERVER['CI_ENV'] 決定的
要設定 $_SERVER['CI_ENV'] 的話,在 Apache 底下是用
SetEnv {VAR_NAME} {VAR_VALUE}
- Nov 05 Thu 2015 10:58
[PHP] Xdebug 的 var_dump 顯示深度設定
因為預設的深度是 3 ,所以如果陣列超過 3 層就會被隱藏。
解決方法:
1. 編輯 php.ini
2. 在 xdebug 的區塊加上
- Oct 24 Sat 2015 23:03
[PHP] 5.5 已內建 opcache 機制 (筆記待整理)
- Aug 28 Fri 2015 23:52
[PHP] json_encode 輸出方便閱讀的 Json 格式
語法如下:
<?php $arr = [ 'a' => 1, 'b' => 2, 'c' => [ 'd' => 3, 'e' => 44 ] ]; echo json_encode($arr, JSON_PRETTY_PRINT); /* output: { "a": 1, "b": 2, "c": { "d": 3, "e": 44 } } */
- Aug 22 Sat 2015 15:29
[PHP] Laravel 5 取得最後查詢的 SQL 語法(Last Query)
語法如下:
// 需要先開啟 Query Log 功能 DB::enableQueryLog(); // 取得所有 Query $queries = DB::getQueryLog(); // 顯示最後一個 SQL 語法 $last_query = end($queries); echo $last_query;
- Jul 14 Tue 2015 18:08
[PHP] Laravel 安裝
相關網址
1. Composer 官網
2. Larabel 官網
- Jul 13 Mon 2015 00:38
[PHP] OOP 概念 - 相依性注入(Dependency Injection)
注意
1. 這篇只是個人的筆記,不保證正確,如需正確版本請多 Google 幾篇 Dependency Injection 的文章來看。
2. 如有錯誤,歡迎指正,我會非常感謝!
參考網址
- Jul 11 Sat 2015 17:50
[PHP] OOP 概念筆記
最近發現自己 OO 的概念有些不是很正確,就稍微再惡補了解了一下
並使用的自己的語言來描述一次,如有錯誤請指正,謝謝!
以下是簡單的筆記:
1. 封裝(Encapsulation)
- Jul 09 Thu 2015 18:06
[PHP] namespace 筆記
這語法是從 PHP 5.3 之後才開始支援,使用 namespace 可減短 class 名稱,或是在不同 namespace 底下取同樣的 class 名稱
以下是簡單的範例
index.php
- Apr 09 Thu 2015 15:44
[PHP] 冷知識: Class 裡的 self 不管大小寫執可以正常執行
剛才試了一下才發現,原來 PHP Class 裡的關鍵字 self
不管是大寫(SELF), 小寫(self), 還是大小寫混雜(SElf) 都是可以正常執行的
不過似乎大部份習慣的寫法是小寫,總之就只是一個冷知識。
以下是測試的程式碼:
- Apr 07 Tue 2015 15:17
[PHP] PHPUnit 單元測試筆記
最近研究了一下 PHP 的單元測試套件 PHPUnit,以下是簡單的筆記
測試環境
Xampp V5.6.3
- Jan 23 Fri 2015 13:54
[PHP] register_globals 選項已於 PHP 5.4 版移除
今天在設定一些之前寫的舊系統時發現功能怪怪的
看了一下才發現對前取 GET 和 POST 的值是用 register_globals 的取法
也就是如果要取 http://localhost?a=1 的時候,是直接用 $a 而不是 $_GET['a']
想說偷懶先設 .htaccess 開啟
- Dec 28 Sun 2014 01:36
[PHP] 使用一個迴圈或遞迴的九九乘法表
一般在寫九九乘法表通常都是兩個 FOR 迴圈
不過今天在網路上看到有人說可以用一個迴圈,想一想的確也是
以下簡單寫了一下解法
一個FOR迴圈解法