2014年11月29日 星期六
2014年11月28日 星期五
X-Forwarded-For 僞造問題
References :
https://groups.google.com/forum/#!topic/hackingthursday/z8-Vn08i4VY
如何正確的取得使用者 IP? | DEVCORE 戴夫寇爾
Flask apps on Heroku susceptible to IP spoofing
2014年11月27日 星期四
PHP fgetcsv, str_getcsv 中文問題
在 OpenShift 上使用 str_getcsv 時中文會有問題,檔案爲 UTF-8 編碼,locale 爲 zh_TW.UTF-8
PHP 4 使用 fgetcsv
PHP 5 使用 str_getcsv
確定可用代碼 :
References :
linux下,fgetcsv乱码问题 - Alian的专栏 - 博客频道 - CSDN.NET
萬隆小站 • 檢視主題 - [php]fgetcsv 讀入檔案無「「」時,第一字元被刪掉亂碼
[php]UTF-8的fgetcsv函數 @ 清新下午茶 :: 痞客邦 PIXNET ::
PHP 4 使用 fgetcsv
PHP 5 使用 str_getcsv
確定可用代碼 :
function __fgetcsv(& $handle, $length = null, $d = ‘,’, $e = ‘”‘) {
$d = preg_quote($d);
$e = preg_quote($e);
$_line = “”;
$eof=false;
while ($eof != true) {
$_line .= (empty ($length) ? fgets($handle) : fgets($handle, $length));
$itemcnt = preg_match_all(’/’ . $e . ‘/’, $_line, $dummy);
if ($itemcnt % 2 == 0)
$eof = true;
}
$_csv_line = preg_replace(’/(?: |[ ])?$/’, $d, trim($_line));
$_csv_pattern = ‘/(’ . $e . ‘[^' . $e . ']*(?:’ . $e . $e . ‘[^' . $e . ']*)*’ . $e . ‘|[^' . $d . ']*)’ . $d . ‘/’;
preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);
$_csv_data = $_csv_matches[1];
for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) {
$_csv_data[$_csv_i] = preg_replace(’/^’ . $e . ‘(.*)’ . $e . ‘$/s’, ‘$1′, $_csv_data[$_csv_i]);
$_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]);
}
return empty ($_line) ? false : $_csv_data;
}
References :
linux下,fgetcsv乱码问题 - Alian的专栏 - 博客频道 - CSDN.NET
萬隆小站 • 檢視主題 - [php]fgetcsv 讀入檔案無「「」時,第一字元被刪掉亂碼
[php]UTF-8的fgetcsv函數 @ 清新下午茶 :: 痞客邦 PIXNET ::
2014年11月25日 星期二
2014年11月24日 星期一
CodeIgniter api route
http://localhost:81/index.php/api/user/index/1
http://localhost:81/index.php/api/user/1
http://localhost:81/index.php/api/user
Route::any('api/(:any)/(:any)/(:num)', '$1/api/$2/$3');
Route::any('api/(:any)/(:num)', '$1/api/index/$2');
Route::any('api/(:any)/(:any)', '$1/api/$2');
Route::any('api/(:any)', '$1/api');
public function index($id = FALSE)
{
$return_data = array('user_id' => $id, 'status' => 'success', message' => '');
echo json_encode($return_data);
}
References :
Parsing URI segments and assigning them to variables - Bonfire Forums
Docs - My Bonfire
JavaScript pass arguments in setInterval function
setInterval( function() { funca(10,3); }, 500 );
References :
javascript - Pass parameters in setInterval function - Stack Overflow
2014年11月20日 星期四
CodeIgniter load a model from another module
$this->load->model('person/person_model');
References :
How to load a model from another module with CodeIgniter - Stack Overflow
CodeIgniter Fatal error: Call to undefined function now()
$this->load->helper('date');
References :
php - Inserting NOW() into Database with CodeIgniter's Active Record - Stack Overflow
2014年11月19日 星期三
PHP if words in string
function contains($needle, $haystack) { return strpos($haystack, $needle) !== false; }
if(contains('bb', 'aa bb cc')) {
echo 'true';
}
References :
php - Check if string contains specific words? - Stack Overflow
CodeIgniter get all column in table
$this->db->list_fields('table');
References :
php - How to get field names of mysql table in codeigniter? - Stack Overflow
CodeIgniter get post value array
name="id[]" value="1"/> name="id[]" value="2"/> name="id[]" value="3"/>
$id = $this->input->post('id');
References :
php - How can I get post data into an array in CodeIgniter? post items are arrays - Stack Overflow
2014年11月18日 星期二
PHP count file lines
$file = "/tmp/somefile.txt"; $lines = count(file($file)); echo "There are $lines lines in $file";
References :
Count the number of lines in a text file - Totally PHP
PHP read file line by line
$file = fopen("/tmp/test.txt","r");
while(!feof($file))
{
echo fgets($file). "
";
}
fclose($file);
References :
PHP fgets() Function
2014年11月17日 星期一
CodeIgniter get login user id
php echo $this->session->userdata('user_id'); ?>
References :
mysql - Add user id to session data (codeigniter) - Stack Overflow
2014年11月16日 星期日
CodeIgniter get insert id
$this->xxx_model->insert($data);
$this->db->insert_id();
References :
php - CodeIgniter activerecord, retrieve last insert id? - Stack Overflow
CodeIgniter SESSION
$this->load->library("session"); // if you not load
$this->session->set_userdata("SESSION_NAME","VALUE");
echo $this->session->userdata("SESSION_NAME");
References :
php - How to save and extract session data in codeigniter - Stack Overflow
2014年11月14日 星期五
2014年11月13日 星期四
Install PHP GD image library
PHP Fatal error: Call to undefined function imagefontwidth()
PHP Fatal error:
Call to undefined function imagecreatefrompng()
Debian / Ubuntu :
# apt-get install php5-gd
# /etc/init.d/apache2 restart
CentOS :
# yum install php-gd
References :
php - Install GD library and freetype on Linux - Stack Overflow
2014年11月11日 星期二
Ubuntu install snmpd
# apt-get install snmp snmpd
# vi /etc/snmp/snmpd.conf
# /etc/init.d/snmpd restart
# Listen for connections from the local system only #agentAddress udp:127.0.0.1:161 # Listen for connections on all interfaces (both IPv4 *and* IPv6) agentAddress udp:161,udp6:[::1]:161
References :
How To Install and Configure an SNMP Daemon and Client on Ubuntu 14.04 | DigitalOcean
Docker run image bind UDP port
$ docker run -p 161:161/udp snmpd
References :
Dnamically bind both tcp and udp on a same port · Issue #4635 · docker/docker
Docker failed to load system roots and no roots provided
Get https://index.docker.io/v1/repositories/ubuntu/images: x509: failed to load system roots and no roots provided
References :
/ccmp/tech: 5月 2014
# apt-get install ca-certificates
# /etc/init.d/docker restart
References :
/ccmp/tech: 5月 2014
Git https verify error
fatal: unable to access 'https://github.com/pozgo/docker-snmpd.git/': Problem with the SSL CA cert (path? access rights?)
References :
git - SSL certificate rejected trying to access GitHub over HTTPS behind firewall - Stack Overflow
$ export GIT_SSL_NO_VERIFY=true
$ git clone https://github.com/pozgo/docker-snmpd.git/
References :
git - SSL certificate rejected trying to access GitHub over HTTPS behind firewall - Stack Overflow
SQLAlchemy query where not null
seats = Seat.query.filter(Seat.invite != None).all()
References :
ython - flask sqlalchemy querying a column with not equals - Stack Overflow
2014年11月10日 星期一
Bonfire database migration
- Enter Web, Database / Database Tools / Migrations
http://localhost/index.php/admin/developer/migrations - auto
migrates
$ vi application/config/config.php
$config['migrate.auto_core'] = TRUE; $config['migrate.auto_app'] = FALSE;
References :
Docs - My Bonfire
Bonfire Unable to locate proper database settings. Please verify settings and reload the page.
$ cp application/config/database.php application/config/development/database.php
References :
Docs - My Bonfire
2014年11月8日 星期六
Yii Gii You are not allowed to access this page.
$ vi test_project/protected/config/main.php
return array( ...... 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'pick up a password here', 'ipFilters'=>false, // 'newFileMode'=>0666, // 'newDirMode'=>0777, ), ), );
References :
php - gii not working in yii - Stack Overflow
2014年11月7日 星期五
Yii CDbConnection failed to open the DB connection.
Yii 預設使用 SQLite Database,PHP 需要安裝函式庫
PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/demos/blog/protected/data/dbgen.php:7
PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/demos/blog/protected/data/dbgen.php:7
# apt-get install sqlite php5-sqlites
# /etc/init.d/apache2 restart
2014年11月5日 星期三
add PPA GPG key
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9D1A0061
References :
[SOLVED] how to add the PPA key
2014年11月3日 星期一
command line send message to IRC
#!/bin/bash
IRC_SERVER='irc.freenode.net'
IRC_PORT=6667
IRC_USERNAME='h4'
IRC_FULLNAME='h4'
IRC_NICK='h4'
IRC_CHANNEL='#h4'
send_irc_message() {
message=$1
echo -e "USER $IRC_USERNAME 8 * : $IRC_FULLNAME\nNICK $IRC_NICK\nJOIN $IRC_CHANNEL\nPRIVMSG :$IRC_CHANNEL $1\nQUIT\n" | nc $IRC_SERVER $IRC_PORT
}
send_irc_message test
References :
ubuntu - Send message to IRC channel from bash - Server Fault
Nunca — Sending messages to an IRC server from a shell script (Bash)
訊息空格問題
sockets - IRC BOT (python) - Stack Overflow
command line convert date string to timestamp
$ date --date='06/12/2012 07:21:22' +"%s"
References :
shell - Convert date time string to UNIX timestamp in bash command - Stack Overflow
訂閱:
文章 (Atom)