[jQuery] AJAX跨網域 | AJAX Cross Domain Request withCredentials (Access-Control-Allow-Origin)

做個AJAX跨網域可是容易忘記細節的,這就來篇Note, 後端部分,Server Header請開啟(以PHP動態Header為例): header(“Access-Control-Allow-Origin: *”); header(“Access-Control-Allow-Credentials: true”); Cookie夾帶 如需夾帶Cookie則前端的AJAX需開啟Credentials,JQuery為例: $.ajax({ xhrFields: { withCredentials: true }, type: “GET”, url: “http://www.example.org/ajax.php” }).done(function (data) { console.log(data); }); xhrFields中withCredentials要開啟,這就是亮點!

[PHP] 匯出處理 – CSV、EXCEL匯出實例教學

Intro 針對使用PHP處理CSV、EXCEL輸出的基礎程式,以及實作上使用之套件。 現行建議使用套件做匯出匯入,可使用yidas/csv-php , Phpspreadsheet-helper。 輸出Header 以CSV為例,PHP的Header與輸出如下: header(“Content-type: text/x-csv”); header(“Content-Disposition: attachment; filename=$filename”); echo $content; exit; 檔案格式介紹: 格式 Type 相隔符號 CSV text/x-csv , SXW application/octet-stream Word application/msword Excel .xls application/vnd.ms-excel \t Excel .xlsx application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Incomplete list of MIME types 編碼轉換: 內容有中文的話得考慮編碼轉換: […]

[Yii2] Composer bower-asset 更新失敗解法

遇到的Composer update問題: yiisoft/yii2 2.*.* requires bower-asset/jquery *.*.*@stable | … -> no matching package found. Yii官網解:composer global require fxp/composer-asset-plugin 本篇是針對不使用Plugin提供解法。 原因: bower-asset在Packagist已經是Virtual Package,以下為bower因果: Update: bower 在 0.9.0 版以前可以使用 component.json,但是為了避免跟其他工具命名衝突,故 0.9.0 以後版本請改為 bower.json bower 是 Twitter 團隊開發的一套網頁工具,用來管理或安裝 Web 開發所需要的 Package,像是 CSS 和 […]

[PHP] magicQuote.php – 用PHP實作magic_quotes_gpc (適用於新環境舊架構)

Magic Quote新版PHP已不支援,但如果遇到舊架構放新環境,還是在Bootstrap就模擬Magic Quote即可治標。 PHP官方Magic Quote: Warning: This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. 以下為遞迴對輸入做addslashes處理達到magic_quotes_gpc: function addslashesRecursively(&$data) { // print_r($data);exit; if (!is_array($data)) { $data = addslashes($data); } else { foreach ($data as $key […]

[PHP] 註解規則表 – PHP Comment

以下為PHP註解規格,可用於宣告變數(Variable)、方法函數(Function)或類別(Class)中: /** * 函數名稱 * 函數描述(有些會含HTML代碼) * * @access 變數可存取的權限 (Example: Public or Private) * @api 爲第三方來源的變數 * @author 函數建立者名稱 (Example: @author Nick Tsai ) * @category 函數的分類別名,可能某些工具會利用這個來分類你的方法,使好幾個方法歸為某一類,方便做辨識使用 * @copyright 函數的版權宣告 (Example: @copyright Code.YIDAS code.yidas.com) * @deprecated 代表不建議使用的函數,未來可能會移除這個方法使用到的某個變數,或整個方法都被刪除 * @example […]

[PHP] 數學數字格式函數彙整 – Numeric Format Functions – (小數點.etc)

number_format() 千分位數值格式 數字格式化,千位分組,支援小數點。 echo number_format(1000.123, 2) = //1,000.12 echo number_format(1000.123, 2, ‘.’, ”); //1000.12 echo number_format(1000.123, 2, ‘,’, ”); //1000,12 sprintf 格式化數字 sprintf(“%05d”, 25); //Output: 00025 整數進位 round() //四捨五入,支援小數位數 ceil() //無條件進入 floor() //無條件捨去

[WordPress] wp_head()函數 – 產生Html Title核心程式碼解析

要找出產生Html Title的核心程式碼,從大多樣板header.php中的wp_head()下去追。 wp_head() //可產生Title tag # wp-includes/general-template.php function wp_head() { … do_action( ‘wp_head’ ); } wp_head()函數是去 do_action: ‘wp_head’。 而在wp_head action中,Title要用的hook為: _wp_render_title_tag # wp-includes\default-filters.php add_action( ‘wp_head’, ‘_wp_render_title_tag’, 1 ); Hook: _wp_render_title_tag # wp-includes/general-template.php function _wp_render_title_tag() { … echo ‘<title>’ . wp_get_document_title() […]

[WordPress] 辨識目前頁面 – is_category() – 免外掛做SEO

先提供目前WordPress辨識所在導航的函數: # 文章分類頁面: is_category() # 首頁: is_home() # 文章&頁面: is_single() is_page() 在主題模板header.php內就可以利用以上做SEO。 Header範例: <?php if (is_home()) { ?> <meta name=”description” content=”首頁顯示描述” /> <?php } ?></blockquote> 其他應用可參考(對自訂欄位$key做應用): http://www.arno.tw/custom-meta-without-plug-in/