CodeIgniter3.0將Session寫入DB

[sql]
CREATE TABLE IF NOT EXISTS `ci_sessions` (
`id` varchar(40) NOT NULL,
`ip_address` varchar(45) NOT NULL,
`timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
`data` blob NOT NULL,
PRIMARY KEY (id),
KEY `ci_sessions_timestamp` (`timestamp`)
);
[/sql]
修改 application/config/config.php
[php]
$config[‘sess_driver’] = ‘database’;
$config[‘sess_save_path’] = ‘ci_sessions’;
[/php]

讓資料庫密碼加上鹽(Salt)值

以往許多人喜歡在資料庫的密碼欄使用明碼儲存,但站在資訊安全角度來說不是挺安全的,可以產生一個Salt值後,增加安全性。
[php]
// 隨機產生一組長度為10的Salt值
$salt = substr(md5(uniqid(rand(), true)), 0, 10);
// 存入資料庫的密碼欄,使用Salt值加上md5雜湊後存回資料庫
$new_password = md5(md5($old_password.$salt));
[/php]
使用者登入後,先從資料庫讀出salt值,接著再一樣加上salt值加上md5後比對就可以了!

CodeIgniter使用PHPExcel製作Excel

1 下載PHPExcel,將PHPExcel解壓縮到Application的third_party目錄下
2 在libraries目錄下新增 excel.php
[php]
<?php
if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

require_once APPPATH."/third_party/PHPExcel.php";

class Excel extends PHPExcel {
public function __construct() {
parent::__construct();
}
}
?>
[/php]
使用
[php]
function createexcel(){
// 產生php 範例
$this->load->library(‘excel’);
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue(‘A1’, ‘中文’);
$objPHPExcel->getActiveSheet()->setCellValue(‘B2’, ‘許’);
$objPHPExcel->getActiveSheet()->setCellValue(‘C3’, ‘test3’);
$objPHPExcel->getActiveSheet()->setCellValue(‘D3’, ‘test4’);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007’);

header(‘Content-Type: application/vnd.ms-excel’);
header(‘Content-Disposition: attachment;filename="excel_report_’ . date(‘ymd’) . ‘.xls"’);
// header(‘Content-Disposition: attachment; filename="file.xls"’);
header(‘Cache-Control: max-age=0’);

$objWriter->save(‘php://output’);

}
[/php]

Embarcadero RAD Studio XE8, Delphi XE8, and C++ Builder XE8 Update 1 正式發佈

這次更新分為二種版本,分為有買維護合約且有效期的以及沒有買維護合約的版本。差別如下~

 

General Update 1 Feature and Fix List

This update is provided to XE8 customers without an Update Subscription

Click here for the download.

  • Community toolbar
  • iOS 8 simulator fix
  • Several files missing from the initial XE8 delivery

Subscription Update 1 Features and Fix List

This update is provided to active Update Subscription customers

Click here for the download.

  • Community toolbar
  • Favorites in welcome page
  • Fast search of Bluetooth LE devices
  • iOS 8 simulator support
  • Improved robustness of IDE productivity features
  • Improvements in multi-device previews

延伸連結

Fix List for XE8 Update 1:
http://edn.embarcadero.com/article/44470

PHP透過curl上傳xml給API

[php]

<?php
$xml_data ='<?xml version="1.0" encoding="UTF-8"?>
<FILE>
<HEAD>
<FILEDESC>ORDER</FILEDESC>
</HEAD>
<CONTENT>
<DATA>
<ID>XXXX</ID>
<MEMO>XXXXXXX</MEMO>
</DATA>
</CONTENT>
</FILE>
‘;

$URL = "http://apisite";

$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: text/xml’));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
[/php]

CodeIgniter發送台灣簡訊範例

[php]
<?php
$username = "xxx"; // 帳號
$password = "xxx"; // 密碼
$mobile = "09xxxxxxxx"; // 電話
$message = "測試簡訊"; // 簡訊內容
$MSGData = "";

$msg = "username=".$username."&password=".$password."&mobile=".$mobile."&message=".urlencode($message)."&drurl=".urlencode("http://xxxx.com.tw/admin/drul/");
$num = strlen($msg);

// 打開 API 閘道
$fp = fsockopen ("api.twsms.com", 80);
if ($fp) {
$MSGData .= "POST /smsSend.php HTTP/1.1\r\n";
$MSGData .= "Host: api.twsms.com\r\n";
$MSGData .= "Content-Length: ".$num."\r\n";
$MSGData .= "Content-Type: application/x-www-form-urlencoded\r\n";
$MSGData .= "Connection: Close\r\n\r\n";
$MSGData .= $msg."\r\n";
fputs ($fp, $MSGData);
$Tmp ="";
// 取出回傳值
while (!feof($fp)) $Tmp.=fgets($fp,128);
$temp2 = explode(PHP_EOL, $Tmp);
// 關閉閘道
fclose ($fp);
/*
0 傳送完成:HTTP/1.1 200 OK
1 Date: Wed, 03 Jun 20xx 09:31:36 GMT
2 Server: Apache
3 X-Powered-By: PHP/5.2.12
4 Connection: close
5 Transfer-Encoding: chunked
6 Content-Type: text/html
7
8 51
9 <smsResp><code>00000</code><text>Success</text><msgid>188xxxx69</msgid></smsResp>
10 0
*/
$xml = simplexml_load_string($temp2[9]);
$xmldata = json_decode( json_encode($xml) , 1);
echo "傳送完成:".$Tmp."<br/>".$xmldata[‘msgid’];
} else {
echo "您無法連接 TwSMS API Server";
}
$this->load->view(‘welcome_message’,$data);

}

public function drul(){
$this->load->database();
$inputdata = $this->input->get(‘xml’);
$xml = simplexml_load_string($inputdata);
$xmldata = json_decode( json_encode($xml) , 1);
$arraystring =print_r($xmldata);
$this->msg=$arraystring;

$dbvalue = array(
‘sms_msg’=> $xmldata[‘msgid’]."status=".$xmldata[‘statustext’],
‘id’ =>$xmldata[‘code’],
‘ip’ => $this->input->ip_address(),
);
$this->db->insert(‘drul’,$dbvalue );
$data = array(
‘message’ => $xmldata[‘msgid’]
);
$this->load->view(‘welcome_message’,$data);
}
[/php]

CodeIgniter超簡易發信

[php]
$email_config = Array(
‘mailtype’ => ‘html’

);
$this->load->library(’email’,$email_config);
$this->email->from(‘superlevin@gmail.com’, ‘林壽山’); //寄件者
$this->email->to(‘123@gmail.com’); // 收件者
//$this->email->cc(‘123cc@gmail.com’); // 副本
//$this->email->bcc(‘123bcc@gmail.com’); // 密件副本

$this->email->subject(‘成功通知信’); // 主旨
$this->email->message(‘<b>報名成功</b>’); //內容
$this->email->send();
[/php]

CodeIgniter上傳圖檔以及縮圖

[php]
// 縮圖
function _createThumbnail($fileName, $isThumb, $thumbMarker="", $width, $height) {
// 參數
$config[‘image_library’] = ‘gd2’;
$config[‘source_image’] = $fileName;
$config[‘create_thumb’] = $isThumb;
$config[‘maintain_ratio’] = TRUE;
$config[‘master_dim’] = ‘width’;
if(isset($thumbMarker) && $thumbMarker!=""){
$config[‘thumb_marker’] = $thumbMarker;
}
$config[‘width’] = $width;
$config[‘height’] = $height;

$this->load->library(‘image_lib’, $config);
$this->image_lib->clear();
$this->image_lib->initialize($config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}
[/php]
上傳
[php]
function uploadimage(){
$name = $this->input->get_post(‘my_file’);
$config[‘upload_path’] = ‘./uploads/’;
$config[‘allowed_types’] = ‘gif|jpg|png’;
$config[‘file_name’] = $name;
$config[‘overwrite’] = true;
$config[‘max_size’] = 4096;
//$config[‘max_width’] = 5000;
//$config[‘max_height’] = 5000;
$this->load->library(‘upload’, $config);
if ( ! $this->upload->do_upload())
{
$data[‘errormsg’] = array(‘error’ => $this->upload->display_errors());
$this->load->view(‘welcome_message’, $data);
}
else
{
$fInfo = $this->upload->data();
$this->_createThumbnail($fInfo[‘full_path’],TRUE,"",330,480);
$this->_createThumbnail($fInfo[‘full_path’],TRUE,"_tn",110,160);

$data[‘filename’]=$this->upload->data(‘file_name’);
$this->load->view(‘welcome_message’,$data);
}

}
[/php]

法國商使用Delphi結合UV感測器發表智慧型比基尼

法國公司Spinali Design發表了智慧型比基尼泳衣,使用Delphi結合UV 感測器開發app,如果穿載者紫外線過度 提醒穿戴者紫外線過度,並適時提醒補充防曬乳。

在影片中,32秒、40秒及55秒等多處都 可以看到Delphi IDE現身。

新聞網址:
http://www.telegraph.co.uk/news/worldnews/europe/france/11667659/Intelligent-French-bikini-warns-bathers-over-too-much-sun.html