Skip to content

Instantly share code, notes, and snippets.

@mly520
Created June 26, 2013 11:29
Show Gist options
  • Save mly520/5866717 to your computer and use it in GitHub Desktop.
Save mly520/5866717 to your computer and use it in GitHub Desktop.
php ci libaray
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* KAI eCRM
*
* 画像操作クラス
*
* @package application
* @author an
* @version 1.0α
* @filesource
*/
// ------------------------------------------------------------------------
/**
* 画像操作クラス
*
* 1.画像のリサイズ
* 2.サムネイルの作成
*
* @package application
* @subpackage libraries
* @category libraries
* @author an
*/
class Convert_image {
var $CI;
/**
* Constructor
*
*/
function Convert_image()
{
$this->CI =& get_instance();
// ファイルクラスをロード
$this->CI->load->helper(array('string', 'file'));
// アップロードクラスをロード
$this->CI->load->library('upload');
// 画像操作クラスのロード
$this->CI->load->library('image_lib');
}
// --------------------------------------------------------------------
/**
* 画像処理(一つ画像を作成)
*
* @access private
* @param array $config_info アップロードの設定情報
* @return string 画像のパス
*/
function resize($config_info)
{
log_message('info', __METHOD__ . '[' . __LINE__ . '] - Enter...');
// ログ出力
log_message('debug', __METHOD__ . '[' . __LINE__ . '] - ' . print_r($config_info, TRUE));
// アップロードクラスの設定
$config['overwrite'] = FALSE;
$config['encrypt_name'] = TRUE;
$config['upload_path'] = $config_info['upload_path']; // ディレクトリ
$config['allowed_types'] = $config_info['allowed_types']; // 許可するタイプ
// アップロードクラスを設定
$this->CI->upload->initialize($config);
// アップロードファイルパス
$upload_path = $config_info['upload_path'];
// 画像の幅最大値
$image_max_width = $config_info['max_width'];
// 画像の高さ最大値
$image_max_height = $config_info['max_height'];
// ファイルのフィールド名を取得
$field_name = $config_info['field_name'];
// アップロードの処理
if ( ! $this->CI->upload->do_upload($field_name))
{
// エラーの場合
$error = $this->CI->upload->display_errors();
// ログ出力
log_message('error', __METHOD__ . '[' . __LINE__ . '] - ' . print_r($error, TRUE));
$upload_file_name['error'] = $error;
return $upload_file_name;
}
// 成功した場合、アップロードされたファイルの情報を取得
$upload_data = $this->CI->upload->data();
// ログ出力
log_message('debug', __METHOD__ . '[' . __LINE__ . '] - ' . print_r($upload_data, TRUE));
// アップロードされたファイルの拡張子を含むファイル名
$file_name = $upload_data['file_name'];
// ファイル名を含むサーバ上のファイルへの絶対パスを取得
$file_path_name = $upload_data['full_path'];
// 画像の幅を取得
$image_width_original = $upload_data['image_width'];
// 画像の高さを取得
$image_height_original = $upload_data['image_height'];
// 「リサイズ」画像を作成 開始
$proportion = $this->_resize_proportion($image_width_original, $image_height_original, $image_max_width, $image_max_height);
// リサイズ比率が0以上の場合、そのサイズへファイルをリサイズする
if ($proportion > 0)
{
// 画像の幅(新しい)
$image_width = (int)($image_width_original * $proportion);
// 画像の高さ (新しい)
$image_height = (int)($image_height_original * $proportion);
}
else
{
// 画像の幅
$image_width = $image_width_original;
// 画像の高さ
$image_height = $image_height_original;
}
// 「リサイズ」画像設定内容
$config['image_library'] = 'gd2';
$config['source_image'] = $file_path_name;
$config['maintain_ratio'] = TRUE;
$config['width'] = $image_width;
$config['height'] = $image_height;
// 画像操作クラスを設定
$this->CI->image_lib->initialize($config);
// 画像のリサイズ
if ( ! $this->CI->image_lib->resize())
{
// エラーだった場合のエラー表示
$error = $this->CI->image_lib->display_errors();
// ログ出力
log_message('error', __METHOD__ . '[' . __LINE__ . '] - ' . print_r($error, TRUE));
return FALSE;
}
// 「リサイズ」画像を作成 完了
// サーバ上のファイルへの相対パス
$upload_file_name['url'] = base_url().substr($upload_path, stripos($upload_path, '/')). $file_name;
$upload_file_name['file_name'] = $file_name;
// ログ出力
log_message('debug', __METHOD__ . '[' . __LINE__ . '] - ' . $upload_file_name);
log_message('info', __METHOD__ . '[' . __LINE__ . '] - Exit.');
return $upload_file_name;
}
// --------------------------------------------------------------------
/**
* 画像サイズを計算
*
* @access private
* @param string $original_width
* @param string $original_height
* @param string $max_width
* @param string $max_height
* @return string
*/
function _resize_proportion($original_width, $original_height, $max_width, $max_height)
{
log_message('info', __METHOD__ . '[' . __LINE__ . '] - Enter...');
// リサイズ比率
$proportion = 0;
// 画像の幅、画像の高さのサイズを比較する
if ($original_width > $original_height)
{
if ($original_width > $max_width)
{
$proportion = ($max_width / $original_width);
}
elseif ($original_height > $max_height)
{
$proportion = ($max_height / $original_height);
}
}
else
{
if ($original_height > $max_height)
{
$proportion = ($max_height / $original_height);
}
elseif ($original_width > $max_width)
{
$proportion = ($max_width / $original_width);
}
}
log_message('info', __METHOD__ . '[' . __LINE__ . '] - Exit.');
return $proportion;
}
}
// END Convert_image Class
/* End of file Convert_image.php */
/* Location: ./system/application/libraries/Convert_image.php */
<?php
class exception_user_agent_check{
var $userAgent = "";
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
//ユーザーエージェント情報をセットする
function __construct()
{
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
$this->userAgent = mb_convert_encoding($this->userAgent, "EUC-JP", "auto");
$this->userAgent = str_replace("?", " ", $this->userAgent);
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* ユーザーエージェント情報による携帯会社の判定
* $userAgent
* @return ($type)0:pc 1:docomo 2:au 3:softbank
*/
function getusertype()
{
$type = "0";
if(ereg("^DoCoMo", $this->userAgent)){
$type = "1";
}else if(ereg("^J-PHONE|^Vodafone|^SoftBank|^MOT-", $this->userAgent)){
$type = "3";
}else if(ereg("^UP.Browser|^KDDI", $this->userAgent)){
$type = "2";
}
return $type;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* 携帯のフォーム対象チェック
* $userAgent
* @return (true false)
*/
function checkmobileform()
{
$result = false;
if($this->getusertype()=="1")
{
$result = $this->checkdocomo();
}
else if($this->getusertype()=="3")
{
$result = $this->checksoftbank();
}
else if($this->getusertype()=="2")
{
$result = $this->checkau();
}
return $result;
}
/**
* 携帯のフォーム対象チェック
* $userAgent
* @return (true false)
*/
function checkpcform()
{
$result = false;
if($this->getusertype()=="0")
{
$result = true;
}
return $result;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* 携帯のDevice ID を取得する
* $userAgent
* @return ($deviceid)
*/
function getdeviceid()
{
$deviceid = "";
if($this->getusertype()=="1")
{
$agent = str_replace(" ", "/", $this->userAgent);
$agentArray = explode("/", $agent);
$deviceid = $agentArray[2];
if(strpos($deviceid, '(')!=FALSE)
{
$deviceid = substr($deviceid,0,strpos($deviceid, '('));
}
/*if(strpos($this->userAgent, "DoCoMo/1.0") >= 0 && strpos($this->userAgent, "/", 11) >= 0){
$deviceid = substr($this->userAgent, 11, (strpos($this->userAgent, "/", 11) - 11));
}else if(strpos($this->userAgent, "DoCoMo/2.0") >= 0 && strpos($this->userAgent, "(", 11) >= 0){
$deviceid = substr($this->userAgent, 11, (strpos($this->userAgent, "(", 11) - 11));
}else{
$deviceid = substr($this->userAgent, 11);
}*/
}
else if($this->getusertype()=="3")
{
//$agentArray = explode("/", $this->userAgent);
//$deviceid = $agentArray[2];
$deviceid = $_SERVER{'HTTP_X_JPHONE_MSNAME'};
}
else if($this->getusertype()=="2")
{
//$agent = str_replace(" ", "/", $this->userAgent);
//$agentArray = explode("/", $agent);
//$deviceid = substr($agentArray[0], 5);
$deviceid = substr($this->userAgent, (strpos($this->userAgent, "-") + 1), (strpos($this->userAgent, " ") - strpos($this->userAgent, "-") - 1));
}
return $deviceid;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* 携帯の判定
* $userAgent
* @return (true false)
*/
function ismobile()
{
if($this->getusertype()==="0")
{
return false;
}
return true;
}
/**
* PCの判定
* $userAgent
* @return (true false)
*/
function ispc()
{
if($this->ismobile())
{
return false;
}
return true;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* DOCOMOの判定
* $userAgent
* @return (true false)
*/
function checkdocomo()
{
if($this->isfoma())
{
return $this->exceptionmobile($this->getdeviceid());
}
return false;
}
/**
* AUの判定
* $userAgent
* @return (true false)
*/
function checkau()
{
if($this->iswin())
{
return $this->exceptionmobile($this->getdeviceid());
}
return false;
}
/**
* SOFTBANKの判定
* $userAgent
* @return (true false)
*/
function checksoftbank()
{
if($this->is3g())
{
return $this->exceptionmobile($this->getdeviceid());
}
return false;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------
//DOCOMO
//-------------------------------------------------------------------------
/**
* DOCOMOのFOMAの判定
* $userAgent
* @return (true false)
*/
function isfoma()
{
$agent = str_replace(" ", "/", $this->userAgent);
$agentArray = explode("/", $agent);
if ($agentArray[1] == "1.0")
{
return false;
}
return true;
}
//-------------------------------------------------------------------------
//AU
//-------------------------------------------------------------------------
/**
* AUのWINの判定(要検討)
* $userAgent
* @return (true false)
*/
function iswin()
{
/*echo $this->getdeviceid();
echo substr($this->getdeviceid(), 3);die();
if(substr($this->getdeviceid(), 3,1)>=3)
{
return true;
}
return false;*/
//return preg_match("/~KDDI\-/i", $this->userAgent);
return preg_match("/^KDDI\-/i", $this->userAgent);
}
//-------------------------------------------------------------------------
//SOFTBANK
//-------------------------------------------------------------------------
/**
* SOFTBANKの3G判定
* $userAgent
* @return (true false)
*/
function is3g()
{
/*if(preg_match("/^(Softbank|Vodafone|MOT\-[CV]|Vemulator)/i", $agent))
{
return true;
}*/
return preg_match("/^(Softbank|Vodafone|MOT\-[CV]|Vemulator)/i", $this->userAgent);
return false;
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
/**
* 除外機種の判定
* $userAgent
* @return (true false)
*/
function exceptionmobile($deviceid)
{
$this->CI =& get_instance();
$this->CI->load->model('form/exceptionmobile_model');
return $this->CI->exceptionmobile_model->check_exceptionmobile($deviceid);
}
//----------------------------------------------------------------------------------------------------
//■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//----------------------------------------------------------------------------------------------------
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends Controller
{
var $data = array();
function MY_Controller()
{
parent::Controller();
$this->load->library('encrypt');
$this->load->library('session');
$this->load->helper('image');
$this->load->model('member/login_model');
$this->data['user_info'] = $this->user_info();
}
/**
* ログインチェック
*
* @return array
*/
function user_info()
{
$user_info = "";
if( $this->session->userdata(UID) != FALSE )
{
$user_info = $this->login_model->get_user_info();
}
return $user_info;
}
}
?>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* CodeIgniter Encryption Class
*
* Provides two-way keyed encoding using XOR Hashing and Mcrypt
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/libraries/encryption.html
*/
class MY_Encrypt extends CI_Encrypt {
var $CI;
var $encryption_key = '';
var $_hash_type = 'sha1';
var $_mcrypt_exists = FALSE;
var $_mcrypt_cipher;
var $_mcrypt_mode;
/**
* Constructor
*
* Simply determines whether the mcrypt library exists.
*
*/
function MY_Encrypt()
{
$this->CI =& get_instance();
$this->_mcrypt_exists = FALSE;
log_message('debug', "Encrypt Class Initialized");
}
// --------------------------------------------------------------------
/**
* Fetch the encryption key
*
* Returns it as MD5 in order to have an exact-length 128 bit key.
* Mcrypt is sensitive to keys that are not the correct length
*
* @access public
* @param string
* @return string
*/
function get_key($key = '')
{
if ($key == '')
{
if ($this->encryption_key != '')
{
return $this->encryption_key;
}
$CI =& get_instance();
$key = $CI->config->item('encryption_key');
if ($key === FALSE)
{
show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
}
}
return md5($key);
}
// --------------------------------------------------------------------
/**
* Set the encryption key
*
* @access public
* @param string
* @return void
*/
function set_key($key = '')
{
$this->encryption_key = $key;
}
// --------------------------------------------------------------------
/**
* Encode
*
* Encodes the message string using bitwise XOR encoding.
* The key is combined with a random hash, and then it
* too gets converted using XOR. The whole thing is then run
* through mcrypt (if supported) using the randomized key.
* The end result is a double-encrypted message string
* that is randomized with each call to this function,
* even if the supplied message and key are the same.
*
* @access public
* @param string the string to encode
* @param string the key
* @return string
*/
function encode($string, $key = '')
{
$key = $this->get_key($key);
$enc = $this->_xor_encode($string, $key);
if ($this->_mcrypt_exists === TRUE)
{
$enc = $this->mcrypt_encode($enc, $key);
}
return base64_encode($enc);
}
// --------------------------------------------------------------------
/**
* Decode
*
* Reverses the above process
*
* @access public
* @param string
* @param string
* @return string
*/
function decode($string, $key = '')
{
$key = $this->get_key($key);
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
{
return FALSE;
}
$dec = base64_decode($string);
if ($this->_mcrypt_exists === TRUE)
{
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
return FALSE;
}
}
return $this->_xor_decode($dec, $key);
}
// --------------------------------------------------------------------
/**
* XOR Encode
*
* Takes a plain-text string and key as input and generates an
* encoded bit-string using XOR
*
* @access private
* @param string
* @param string
* @return string
*/
function _xor_encode($string, $key)
{
$rand = '';
while (strlen($rand) < 32)
{
$rand .= mt_rand(0, mt_getrandmax());
}
$rand = $this->hash($rand);
$enc = '';
for ($i = 0; $i < strlen($string); $i++)
{
$enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
}
return $this->_xor_merge($enc, $key);
}
// --------------------------------------------------------------------
/**
* XOR Decode
*
* Takes an encoded string and key as input and generates the
* plain-text original message
*
* @access private
* @param string
* @param string
* @return string
*/
function _xor_decode($string, $key)
{
$string = $this->_xor_merge($string, $key);
$dec = '';
for ($i = 0; $i < strlen($string); $i++)
{
$dec .= (substr($string, $i++, 1) ^ substr($string, $i, 1));
}
return $dec;
}
// --------------------------------------------------------------------
/**
* XOR key + string Combiner
*
* Takes a string and key as input and computes the difference using XOR
*
* @access private
* @param string
* @param string
* @return string
*/
function _xor_merge($string, $key)
{
$hash = $this->hash($key);
$str = '';
for ($i = 0; $i < strlen($string); $i++)
{
$str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Encrypt using Mcrypt
*
* @access public
* @param string
* @param string
* @return string
*/
function mcrypt_encode($data, $key)
{
$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
$init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND);
return $this->_add_cipher_noise($init_vect.mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), $key);
}
// --------------------------------------------------------------------
/**
* Decrypt using Mcrypt
*
* @access public
* @param string
* @param string
* @return string
*/
function mcrypt_decode($data, $key)
{
$data = $this->_remove_cipher_noise($data, $key);
$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
if ($init_size > strlen($data))
{
return FALSE;
}
$init_vect = substr($data, 0, $init_size);
$data = substr($data, $init_size);
return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
}
// --------------------------------------------------------------------
/**
* Adds permuted noise to the IV + encrypted data to protect
* against Man-in-the-middle attacks on CBC mode ciphers
* http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
*
* Function description
*
* @access private
* @param string
* @param string
* @return string
*/
function _add_cipher_noise($data, $key)
{
$keyhash = $this->hash($key);
$keylen = strlen($keyhash);
$str = '';
for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
{
if ($j >= $keylen)
{
$j = 0;
}
$str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Removes permuted noise from the IV + encrypted data, reversing
* _add_cipher_noise()
*
* Function description
*
* @access public
* @param type
* @return type
*/
function _remove_cipher_noise($data, $key)
{
$keyhash = $this->hash($key);
$keylen = strlen($keyhash);
$str = '';
for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
{
if ($j >= $keylen)
{
$j = 0;
}
$temp = ord($data[$i]) - ord($keyhash[$j]);
if ($temp < 0)
{
$temp = $temp + 256;
}
$str .= chr($temp);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Set the Mcrypt Cipher
*
* @access public
* @param constant
* @return string
*/
function set_cipher($cipher)
{
$this->_mcrypt_cipher = $cipher;
}
// --------------------------------------------------------------------
/**
* Set the Mcrypt Mode
*
* @access public
* @param constant
* @return string
*/
function set_mode($mode)
{
$this->_mcrypt_mode = $mode;
}
// --------------------------------------------------------------------
/**
* Get Mcrypt cipher Value
*
* @access private
* @return string
*/
function _get_cipher()
{
if ($this->_mcrypt_cipher == '')
{
$this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256;
}
return $this->_mcrypt_cipher;
}
// --------------------------------------------------------------------
/**
* Get Mcrypt Mode Value
*
* @access private
* @return string
*/
function _get_mode()
{
if ($this->_mcrypt_mode == '')
{
$this->_mcrypt_mode = MCRYPT_MODE_ECB;
}
return $this->_mcrypt_mode;
}
// --------------------------------------------------------------------
/**
* Set the Hash type
*
* @access public
* @param string
* @return string
*/
function set_hash($type = 'sha1')
{
$this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type;
}
// --------------------------------------------------------------------
/**
* Hash encode a string
*
* @access public
* @param string
* @return string
*/
function hash($str)
{
return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str);
}
// --------------------------------------------------------------------
/**
* Generate an SHA1 Hash
*
* @access public
* @param string
* @return string
*/
function sha1($str)
{
if ( ! function_exists('sha1'))
{
if ( ! function_exists('mhash'))
{
require_once(BASEPATH.'libraries/Sha1'.EXT);
$SH = new CI_SHA;
return $SH->generate($str);
}
else
{
return bin2hex(mhash(MHASH_SHA1, $str));
}
}
else
{
return sha1($str);
}
}
}
// END CI_Encrypt class
/* End of file Encrypt.php */
/* Location: ./system/libraries/Encrypt.php */
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
*
* ■DB関連共通■
*
*/
class MY_Model extends Model {
function MY_Model()
{
parent::Model();
//DB接続オブジェクト作成する
$this->load->database();
}
//都府県マスター情報取得
function get_prefecture_mst_info()
{
$this->db->select('pref_no,pref_name');
$this->db->from('prefecture_mst');
$this->db->where('enable', 1);
$this->db->where('use_flg', 1);
$this->db->order_by("pref_no", "asc");
$query = $this->db->get();
return $query->result_array();
}
//メール送信処理
function send_kai_mail( $ftsmt )
{
$msg = file_get_contents(VIEWS_PATH."mail_tpl/".$ftsmt['mail_tpl']);
foreach( $ftsmt['msg'] as $key=>$temp)
{
$replace = "###".$key."###";
$msg = str_replace($replace, $temp, $msg);
$msg = mb_convert_kana($msg, "K");
}
$ftsmt['cc'] = (isset($ftsmt['cc'])) ? $ftsmt['cc'] : '';
$ftsmt['bcc'] = (isset($ftsmt['bcc'])) ? $ftsmt['bcc'] : '';
$subject = $ftsmt['subject'];
$body = $msg;
//メール送信
mb_language('Japanese'); //ISO-2022-JP
mb_internal_encoding('UTF-8');
$header="From: " .mb_encode_mimeheader($ftsmt['from_name']) . "<" . $ftsmt['from'] . ">";
$header.="\n";
$header.="Cc: ".$ftsmt['cc'];
$header.="\n";
$header.="Bcc: ".$ftsmt['bcc'];
$res = mb_send_mail($ftsmt['to'], $subject, $body, $header);
return $res;
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Session Class
*
* This is extended from the default Session class in CodeIgniter 1.7.1.
*
* It fixes the serialization of Objects:
* REF: http://codeigniter.com/forums/viewthread/95690/
* BUG: http://codeigniter.com/bug_tracker/bug/7145/
* BUG: http://codeigniter.com/bug_tracker/bug/5758/
*
* It makes session expiration handling better:
* http://codeigniter.com/forums/viewthread/109645/
*
* It allows you to override the sess_persistent_cookie value for individual
* sessions.
*
*
* @package CodeIgniter
* @subpackage Libraries
* @category Sessions
* @author Ramesh Nair, HiddenTao Ltd
* @link http://www.hiddentao.com/
*/
class MY_Session extends CI_Session {
var $sess_persistent_cookie = TRUE;
/**
* Session Constructor
*
* The constructor runs the session routines automatically
* whenever the class is instantiated.
*/
function MY_Session($params = array())
{
log_message('debug', "Session Class Initialized");
// Set the super object to a local variable for use throughout the class
$this->CI =& get_instance();
// Set all the session preferences, which can either be set
// manually via the $params array above or via the config file
foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key', 'sess_persistent_cookie') as $key)
{
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
}
// Load the string helper so we can use the strip_slashes() function
$this->CI->load->helper('string');
// Do we need encryption? If so, load the encryption class
if ($this->sess_encrypt_cookie == TRUE)
{
$this->CI->load->library('encrypt');
}
// Are we using a database? If so, load it
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
$this->CI->load->database();
}
// Set the "now" time. Can either be GMT or server time, based on the
// config prefs. We use this to set the "last activity" time
$this->now = $this->_get_time();
// Set the session length. If the session expiration is
// set to zero we'll set the expiration two years from now.
if ($this->sess_expiration == 0)
{
//$this->sess_expiration = (60*60*24*365*2);
$this->sess_expiration = 0;
}
// Set the cookie name
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
// Run the Session routine. If a session doesn't exist we'll
// create a new one. If it does, we'll update it.
if ( ! $this->sess_read())
{
$this->sess_create();
}
else
{
$this->sess_update();
}
// Delete 'old' flashdata (from last request)
$this->_flashdata_sweep();
// Mark all new flashdata as old (data will be deleted before next request)
$this->_flashdata_mark();
// Delete expired sessions if necessary
$this->_sess_gc();
log_message('debug', "Session routines successfully run");
}
// --------------------------------------------------------------------
/**
* Set whether the session should be persisted across browser sessions.
*
* This overrides the 'sess_persistent_cookie' config value for the current
* browser session.
*
* @access public
*
* @param $value if TRUE then the session data will be persisted across
* browser sessions. If FALSE then it won't.
*
* @return void
*/
function sess_persistent_cookie($value)
{
$this->userdata['persistent_cookie'] = $value;
$this->sess_write();
}
// --------------------------------------------------------------------
/**
* Write the session data
*
* @access public
* @return void
*/
function sess_write()
{
// Are we saving custom data to the DB? If not, all we do is update the cookie
if ($this->sess_use_database === FALSE)
{
$this->_set_cookie();
return;
}
// set the custom userdata, the session data we will set in a second
$custom_userdata = $this->userdata;
$cookie_userdata = array();
// Before continuing, we need to determine if there is any custom data to deal with.
// Let's determine this by removing the default indexes to see if there's anything left in the array
// and set the session data while we're at it
foreach (array('session_id','ip_address','user_agent','last_activity','persistent_cookie') as $val)
{
unset($custom_userdata[$val]);
$cookie_userdata[$val] = $this->userdata[$val];
}
// Did we find any custom data? If not, we turn the empty array into a string
// since there's no reason to serialize and store an empty array in the DB
if (count($custom_userdata) === 0)
{
$custom_userdata = '';
}
else
{
// Serialize the custom data array so we can store it
$custom_userdata = $this->_serialize($custom_userdata);
}
// Run the update query
$this->CI->db->where('session_id', $this->userdata['session_id']);
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
// Write the cookie. Notice that we manually pass the cookie data array to the
// _set_cookie() function. Normally that function will store $this->userdata, but
// in this case that array contains custom data, which we do not want in the cookie.
$this->_set_cookie($cookie_userdata);
}
// --------------------------------------------------------------------
/**
* Create a new session
*
* @access public
* @return void
*/
function sess_create()
{
$sessid = '';
while (strlen($sessid) < 32)
{
$sessid .= mt_rand(0, mt_getrandmax());
}
// To make the session ID even more secure we'll combine it with the user's IP
$sessid .= $this->CI->input->ip_address();
$this->userdata = array(
'session_id' => md5(uniqid($sessid, TRUE)),
'ip_address' => $this->CI->input->ip_address(),
'user_agent' => substr($this->CI->input->user_agent(), 0, 50),
'last_activity' => $this->now,
);
// Save the data to the DB if needed
if ($this->sess_use_database === TRUE)
{
$this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata));
}
// add variables which weren't to be stored in the db
$this->userdata['persistent_cookie'] = $this->sess_persistent_cookie;
// Write the cookie
$this->_set_cookie();
}
// --------------------------------------------------------------------
/**
* Update an existing session
*
* @access public
* @return void
*/
function sess_update()
{
// We only update the session every five minutes by default
if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
{
return;
}
// Save the old session id so we know which record to
// update in the database if we need it
$old_sessid = $this->userdata['session_id'];
$new_sessid = '';
while (strlen($new_sessid) < 32)
{
$new_sessid .= mt_rand(0, mt_getrandmax());
}
// To make the session ID even more secure we'll combine it with the user's IP
$new_sessid .= $this->CI->input->ip_address();
// Turn it into a hash
$new_sessid = md5(uniqid($new_sessid, TRUE));
// Update the session data in the session data array
$this->userdata['session_id'] = $new_sessid;
$this->userdata['last_activity'] = $this->now;
// _set_cookie() will handle this for us if we aren't using database sessions
// by pushing all userdata to the cookie.
$cookie_data = NULL;
// Update the session ID and last_activity field in the DB if needed
if ($this->sess_use_database === TRUE)
{
// set cookie explicitly to only have our session data
$cookie_data = array();
foreach (array('session_id','ip_address','user_agent','last_activity','persistent_cookie') as $val)
{
$cookie_data[$val] = $this->userdata[$val];
}
$this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));
}
// Write the cookie
$this->_set_cookie($cookie_data);
}
// --------------------------------------------------------------------
/**
* Fetch the current session data if it exists
*
* @access public
* @return bool
*/
function sess_read()
{
// Fetch the cookie
$session = $this->CI->input->cookie($this->sess_cookie_name);
// No cookie? Goodbye cruel world!...
if ($session === FALSE)
{
log_message('debug', 'A session cookie was not found.');
return FALSE;
}
// Decrypt the cookie data
if ($this->sess_encrypt_cookie == TRUE)
{
$session = $this->CI->encrypt->decode($session);
}
else
{
// encryption was not used, so we need to check the md5 hash
$hash = substr($session, strlen($session)-32); // get last 32 chars
$session = substr($session, 0, strlen($session)-32);
// Does the md5 hash match? This is to prevent manipulation of session data in userspace
if ($hash !== md5($session.$this->encryption_key))
{
log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
$this->sess_destroy();
return FALSE;
}
}
// Unserialize the session array
$session = $this->_unserialize($session);
// Is the session data we unserialized an array with the correct format?
if ( ! is_array($session) OR
!isset($session['session_id']) OR
!isset($session['ip_address']) OR
!isset($session['user_agent']) OR
!isset($session['last_activity']) OR
!isset($session['persistent_cookie'])
)
{
$this->sess_destroy();
return FALSE;
}
// Is the session current?
if (($session['last_activity'] + $this->sess_expiration) < $this->now)
{
$this->sess_destroy();
return FALSE;
}
// Does the IP Match?
if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address())
{
$this->sess_destroy();
return FALSE;
}
// Does the User Agent Match?
if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50)))
{
$this->sess_destroy();
return FALSE;
}
// Is there a corresponding session in the DB?
if ($this->sess_use_database === TRUE)
{
$this->CI->db->where('session_id', $session['session_id']);
if ($this->sess_match_ip == TRUE)
{
$this->CI->db->where('ip_address', $session['ip_address']);
}
if ($this->sess_match_useragent == TRUE)
{
$this->CI->db->where('user_agent', $session['user_agent']);
}
$query = $this->CI->db->get($this->sess_table_name);
// No result? Kill it!
if ($query->num_rows() == 0)
{
$this->sess_destroy();
return FALSE;
}
// Is there custom data? If so, add it to the main session array
$row = $query->row();
if (isset($row->user_data) AND $row->user_data != '')
{
$custom_data = $this->_unserialize($row->user_data);
if (is_array($custom_data))
{
foreach ($custom_data as $key => $val)
{
$session[$key] = $val;
}
}
}
}
// Session is valid!
$this->userdata = $session;
unset($session);
return TRUE;
}
// --------------------------------------------------------------------
/**
* Write the session cookie
*
* @access public
* @return void
*/
function _set_cookie($cookie_data = NULL)
{
if (is_null($cookie_data))
{
$cookie_data = $this->userdata;
}
// Persistent cookie?
if (!$cookie_data['persistent_cookie'])
{
$expiration = 0;
}
else
{
$expiration = $this->sess_expiration + time();
}
// Serialize the userdata for the cookie
$cookie_data = $this->_serialize($cookie_data);
if ($this->sess_encrypt_cookie == TRUE)
{
$cookie_data = $this->CI->encrypt->encode($cookie_data);
}
else
{
// if encryption is not used, we provide an md5 hash to prevent userside tampering
$cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
}
// Set the cookie
setcookie(
$this->sess_cookie_name,
$cookie_data,
$expiration,
$this->cookie_path,
$this->cookie_domain,
0
);
}
// --------------------------------------------------------------------
/**
* Serialize an array
*
* This function first converts any slashes found in the array to a temporary
* marker, so when it gets unserialized the slashes will be preserved
*
* @access private
* @param array
* @return string
*/
function _serialize($data)
{
if (is_array($data))
{
foreach ($data as $key => $val)
{
if (!is_object($val))
$data[$key] = str_replace('\\', '{{slash}}', $val);
}
}
else
{
if (!is_object($data))
$data = str_replace('\\', '{{slash}}', $data);
}
return serialize($data);
}
// --------------------------------------------------------------------
/**
* Unserialize
*
* This function unserializes a data string, then converts any
* temporary slash markers back to actual slashes
*
* @access private
* @param array
* @return string
*/
function _unserialize($data)
{
$data = @unserialize(strip_slashes($data));
if (is_array($data))
{
foreach ($data as $key => $val)
{
if (!is_object($val))
$data[$key] = str_replace('{{slash}}', '\\', $val);
}
return $data;
}
if (!is_object($data))
return str_replace('{{slash}}', '\\', $data);
else
return $data;
}
}
// END Session Class
/* End of file */
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* KAI Font
*
* ファイルアップロード
*
* @package application_jp
* @author an
* @version 1.0α
* @filesource
*/
// ------------------------------------------------------------------------
/**
*
*
* チェック
*
* @package application_jp
* @subpackage libraries
* @category libraries
* @author an
*/
class MY_Upload extends CI_Upload {
/**
* Constructor
*
*/
function MY_Upload()
{
parent::CI_Upload();
}
// --------------------------------------------------------------------
/**
* Verify that the filetype is allowed
*
* @access public
* @return bool
*/
function is_allowed_filetype()
{
if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
{
$this->set_error('upload_no_file_types');
return FALSE;
}
$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');
foreach ($this->allowed_types as $val)
{
$mime = $this->mimes_types(strtolower($val));
// Images get some additional checks
if ($this->is_image())
{
if (in_array($val, $image_types))
{
if (getimagesize($this->file_temp) === FALSE)
{
return FALSE;
}
}
}
if (is_array($mime))
{
if (in_array($this->file_type, $mime, TRUE))
{
return TRUE;
}
}
else
{
if ($mime == $this->file_type)
{
return TRUE;
}
}
}
return FALSE;
}
}
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* KAI Font
*
* チェック
*
* @package application_jp
* @author an
* @version 1.0α
* @filesource
*/
// ------------------------------------------------------------------------
/**
* チェッククラス
*
* チェック
*
* @package application_jp
* @subpackage libraries
* @category libraries
* @author an
*/
class MY_Validation extends CI_validation {
/**
* Constructor
*
*/
function MY_Validation()
{
parent::CI_Validation();
}
// --------------------------------------------------------------------
/**
* 全角カタカナのチェック
*
* @access public
* @param string
* @return bool
*/
function check_full_katakana($str)
{
$strlengh = strlen($str);
$arraylen = preg_match_all('/[ア-ヴ]|[ー]+/u', $str, $result, PREG_SET_ORDER);
$count = 0;
for ($i = 0; $i < $arraylen; $i++)
{
$count = $count + strlen($result[$i][0]);
}
if ($strlengh == $count)
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 半角カタカナのチェック
*
* @access public
* @param string
* @return bool
*/
function check_half_katakana($str)
{
$strlengh = strlen($str);
$arraylen = preg_match_all('/[ア-ン]|[ヲ]+/u', $str, $result, PREG_SET_ORDER);
$count = 0;
for ($i = 0; $i < $arraylen; $i++)
{
$count = $count + strlen($result[$i][0]);
}
if ($strlengh == $count)
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 全半角カタカナのチェック
*
* @access public
* @param string
* @return bool
*/
function check_katakana($str)
{
$strlengh = strlen($str);
$arraylen = preg_match_all('/[ア-ヴ]|[ー]|[ア-ン]|[ヲ]+/u', $str, $result, PREG_SET_ORDER);
$count = 0;
for ($i = 0; $i < $arraylen; $i++)
{
$count = $count + strlen($result[$i][0]);
}
if ($strlengh == $count)
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 全角文字のチェック
*
* @access public
* @param string
* @return bool
*/
function check_zenkaku($str)
{
if (!preg_match("/(?:\xEF\xBD[\xA1-\xBF]|\xEF\xBE[\x80-\x9F])|[\x20-\x7E]/", $str)) {
return true;
}
return false;
}
// --------------------------------------------------------------------
/**
* 電話のチェック
*
* @access public
* @param string
* @return bool
*/
function check_tel($str)
{
// $reg = "/(^(?<!090|080|070)(^\d{2,5}?\-\d{1,4}?\-\d{4}$|^[\d\-]{12}$))|(^(090|080|070)(\-\d{4}\-\d{4}|[\\d-]{13})$)|(^0120(\-\d{2,3}\-\d{3,4}|[\d\-]{12})$)|(^0080\-\d{3}\-\d{4})/";
// $reg = "/(^(0)((\d|\-){1,13})$)/";
$reg = "/^0(\d|\-){9,13}$/";
$result = preg_match($reg, $str);
if ($result == 1)
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 郵便のチェック
*
* @access public
* @param string
* @return bool
*/
function check_zip($str)
{
$reg = "/(^\d{3}\-?\d{4}$)/";
$result = preg_match($reg, $str);
if ($result == 1)
{
return TRUE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* CheckBox Min_check
*
* @access public
* @param string
* @return bool
*/
function checkbox_min_check($str,$val)
{
if (is_array($str))
{
return (count($str) >= $val) ? TRUE : FALSE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* CheckBox Max_check
*
* @access public
* @param string
* @return bool
*/
function checkbox_max_check($str,$val)
{
if (is_array($str))
{
return (count($str) <= $val) ? TRUE : FALSE;
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 画像アップロードファイルのタイプをチェック
*
* @access public
* @param string
* @return bool
*/
function img_type_check($str, $val)
{
//ファイルタイプ
$img_type = '';
if($str != '')
{
$img_type = substr($str, -3);
}
if( $val != '')
{
$val_arr = explode(',', $val);
if(is_array($val_arr) && count($val_arr) > 0)
{
foreach($val_arr as $value)
{
if($value == $img_type)
{
return TRUE;
}
}
return FALSE;
}
}
return FALSE;
}
// --------------------------------------------------------------------
/**
* 過去の日付をチェック
*
* @access public
* @param string
* @return bool
*/
function check_past_day($year)
{
if($_POST['qEBirthdayD']!="" && $_POST['qEBirthdayM']!="")
{
if (mktime(0,0,0,date("m"),date("d"),date("Y")) >= mktime(0,0,0,$_POST['qEBirthdayM'],$_POST['qEBirthdayD'],$year)) {
return true;
} else {
return false;
}
}
return true;
}
// --------------------------------------------------------------------
/**
* 日付の存在性をチェック
*
* @access public
* @param string
* @return bool
*/
function check_exist_date($year)
{
if($_POST['qEBirthdayD']!="" && $_POST['qEBirthdayM']!="")
{
if ( checkdate($_POST['qEBirthdayM'], $_POST['qEBirthdayD'], $year) == false) {
return false;
}else{
return true;
}
}
return true;
}
}
// END MY_Validation Class
/* End of file MY_Validation.php */
/* Location: ./system/application/libraries/MY_Validation.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment