Example for Fatal error: Cannot pass parameter 1 by reference
1. &
/***************Error*******************/
$a = test(array());
echo $a;
function test(&$value=array())
{
return $value;
}
/**********************************/
/***************Correct*******************/
$value=array();
$a =test($value);
print_r ($a);
function test(&$value=array())
{
return $value;
}
/**********************************/
12/22/2014
10/28/2014
How to keep ssh alive on centos
By default, the SSH servers are set to disconnect clients who has been inactive or idle after a certain period of time. In order to keep the ssh session alive, you may configure the ssh server.
You may change the ClientAliveInterval, TCPKeepAlive and ClientAliveCountMax options in the sshd configuration file. After you config your ssh, please do not forget to restart your ssh server.
#sudo vi /etc/ssh/sshd_config
ClientAliveInterval 100
TCPKeepAlive yes
ClientAliveCountMax 99999
#sudo /etc/init.d/sshd restart
You may change the ClientAliveInterval, TCPKeepAlive and ClientAliveCountMax options in the sshd configuration file. After you config your ssh, please do not forget to restart your ssh server.
#sudo vi /etc/ssh/sshd_config
ClientAliveInterval 100
TCPKeepAlive yes
ClientAliveCountMax 99999
#sudo /etc/init.d/sshd restart
10/05/2014
htaccess to redirect to different domain name
In order to implement direction for different domain on htaccess, please use the following configuration.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^aaaa/([0-9]+)\.html$ /index.php?action=A&sid=$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^bbbb/([0-9]+)\.html$ /index.php?action=B&sid=$1 [QSA,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^aaaa/([0-9]+)\.html$ /index.php?action=A&sid=$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^bbbb/([0-9]+)\.html$ /index.php?action=B&sid=$1 [QSA,L]
9/05/2014
Install PHP55 on centos 6 based remi repos
To install php55 on centos, you need download the remi repository. Please follow the following steps to complete:
1. Download repo
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2. Confirm the remi.repo
/etc/yum.repos.d/remi.repo
sudo yum install --enablerepo=remi --enablerepo=remi-php55 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug
4. Confirm the version of php
php --version
Note
Please use the following command if you have installed PHP on your server
yum --enablerepo=remi-php55,remi update php\*
1. Download repo
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
2. Confirm the remi.repo
/etc/yum.repos.d/remi.repo
[remi]3. Install PHP55
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php55]
name=Les RPM de remi de PHP 5.5 pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/php55/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/php55/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
[remi-php56]
name=Les RPM de remi de PHP 5.6 pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/php56/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/php56/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=0
gpgcheck=1
............
sudo yum install --enablerepo=remi --enablerepo=remi-php55 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug
4. Confirm the version of php
php --version
PHP 5.5.16 (cli) (built: Sep 3 2014 20:08:58)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
Note
Please use the following command if you have installed PHP on your server
yum --enablerepo=remi-php55,remi update php\*
8/09/2014
ISSN Number Checker
ISSN numbers consist of 8 digits.
To check validity of an ISSN number enter the 8 digit ISSN number in the box below.
You may also enter one issn with hyphen, e.g. 1694-0814
http://journalseeker.researchbib.com/?action=issnChecker
To check validity of an ISSN number enter the 8 digit ISSN number in the box below.
You may also enter one issn with hyphen, e.g. 1694-0814
http://journalseeker.researchbib.com/?action=issnChecker
6/06/2014
Error: Package: google-chrome-stable-XXXXXXX.x86_64 (google-chrome) Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
When you install chrome on centos, you may require to install : libstdc++.so.6(GLIBCXX_3.4.15)(64bit).
The error may be like:
Error: Package: google-chrome-stable-35.0.1916.114-1.x86_64 (google-chrome)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Now you may try to install chromium compiled for centos.
1. Download
wget http://people.centos.org/hughesjr/chromium/6/x86_64/RPMS/chromium-31.0.1650.63-2.el6.x86_64.rpm
2.install
rpm -ivh chromium-31.0.1650.63-2.el6.x86_64.rpm
Now you may use chrome on your centos.
The error may be like:
Error: Package: google-chrome-stable-35.0.1916.114-1.x86_64 (google-chrome)
Requires: libstdc++.so.6(GLIBCXX_3.4.15)(64bit)
Now you may try to install chromium compiled for centos.
1. Download
wget http://people.centos.org/hughesjr/chromium/6/x86_64/RPMS/chromium-31.0.1650.63-2.el6.x86_64.rpm
2.install
rpm -ivh chromium-31.0.1650.63-2.el6.x86_64.rpm
Now you may use chrome on your centos.
6/05/2014
MYSQL Unix time stamp conversion
When you want to convert the time stamp on mysql, please use the following code
1. time stamp to time
select FROM_UNIXTIME(1425933810);
+---------------------------+
| FROM_UNIXTIME(1425933810) |
+---------------------------+
| 2015-03-10 05:43:30 |
+---------------------------+
1 row in set (0.00 sec)
2. time to time stamp
select UNIX_TIMESTAMP('2015-11-06 10:10:10');
+---------------------------------------+
| UNIX_TIMESTAMP('2015-11-06 10:10:10') |
+---------------------------------------+
| 1446772210 |
+---------------------------------------+
1 row in set (0.00 sec)
1. time stamp to time
select FROM_UNIXTIME(1425933810);
+---------------------------+
| FROM_UNIXTIME(1425933810) |
+---------------------------+
| 2015-03-10 05:43:30 |
+---------------------------+
1 row in set (0.00 sec)
2. time to time stamp
select UNIX_TIMESTAMP('2015-11-06 10:10:10');
+---------------------------------------+
| UNIX_TIMESTAMP('2015-11-06 10:10:10') |
+---------------------------------------+
| 1446772210 |
+---------------------------------------+
1 row in set (0.00 sec)
5/13/2014
configure SVN server
Install
# yum install mod_dav_svn subversion
Configure Apache
#vi /etc/httpd/conf/httpd.conf
LoadModule dav_module modules/mod_dav.so
Configure subversion
# vi /etc/httpd/cond.d/subversion.conf
LoadModule dav_svn_module /usr/lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/httpd/modules/mod_authz_svn.so
...
DAV svn
SVNParentPath /home/svn
< Location /repos>
DAV svn
SVNParentPath /home/svn
#
# # Limit write permission to list of valid users.
# < LimitExcept GET PROPFIND OPTIONS REPORT>
# # Require SSL connection for password protection.
# # SSLRequireSSL
#
# AuthType Basic
# AuthName "Authorization Realm"
# AuthUserFile /path/to/passwdfile
# Require valid-user
#
#
# Order Deny,Allow
# Deny from all
# Allow from 192.168.
#
# < /LimitExcept>
< /Location>
Create repos
# mkdir /home/svn
# svnadmin create /home/svn/Test
# chown -R apache:apache /home/svn/Test
Restart the apache
# service httpd reload
Note:
SVNPath: for single svn project
SVNParentPath: for multiple svn project
If you use SVNParentPath, you should access sub-svn from the browser, or you will get
------------------------------------------------------------
--------------------------------------------------------------------------------------
You should access them by http://localhost/repos/sub-svn
p.s.
Create basic auth
htpasswd -c /path/to/passwdfile svn-admin
IP permisison
Order Deny,Allow
Deny from all
Allow from 192.168.10.126
# yum install mod_dav_svn subversion
Configure Apache
#vi /etc/httpd/conf/httpd.conf
LoadModule dav_module modules/mod_dav.so
Configure subversion
# vi /etc/httpd/cond.d/subversion.conf
LoadModule dav_svn_module /usr/lib/httpd/modules/mod_dav_svn.so
LoadModule authz_svn_module /usr/lib/httpd/modules/mod_authz_svn.so
...
DAV svn
SVNParentPath /home/svn
< Location /repos>
DAV svn
SVNParentPath /home/svn
#
# # Limit write permission to list of valid users.
# < LimitExcept GET PROPFIND OPTIONS REPORT>
# # Require SSL connection for password protection.
# # SSLRequireSSL
#
# AuthType Basic
# AuthName "Authorization Realm"
# AuthUserFile /path/to/passwdfile
# Require valid-user
# Deny from all
# Allow from 192.168.
#
< /Location>
Create repos
# mkdir /home/svn
# svnadmin create /home/svn/Test
# chown -R apache:apache /home/svn/Test
Restart the apache
# service httpd reload
Note:
SVNPath: for single svn project
SVNParentPath: for multiple svn project
If you use SVNParentPath, you should access sub-svn from the browser, or you will get
------------------------------------------------------------
Forbidden
You don't have permission to access /repos on this server.--------------------------------------------------------------------------------------
You should access them by http://localhost/repos/sub-svn
p.s.
Create basic auth
htpasswd -c /path/to/passwdfile svn-admin
IP permisison
Order Deny,Allow
Deny from all
Allow from 192.168.10.126
3/18/2014
Get the client browser language class to realize the Multi-regional and multilingual sites
/**
* /Language.php
* $Date:: #$
* @version $Rev$
* @package Language
*/
namespace utility\i18n;
/**
* Description of Language
*
* @package Language
*/
class Language
{
/**
* Language parameter
*/
const LANGUAGE = 'hl';
/**
* Default Language
*/
const DEFAULT_LANGUAGE = 'en';
/**
* Supported Language List
*
* @var array
*/
private $supportedLanguage = array(
'en' => 'English',
'ja' => '日本語',
'zh' => '中文',
'ko' => '한국어',
);
/**
*
* @var string
*/
private $languge = 'en';
/**
* Language Constructor
*/
public function __construct()
{
$hl = isset($_GET[self::LANGUAGE]) ? $_GET[self::LANGUAGE] : @$_COOKIE[self::LANGUAGE];
if (!$hl) {
$hl = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
$this->setLanguage($hl);
}
/**
* Change the browser language
*
* @param string $hl
* @return \utility\i18n\Language
*/
public function setLanguage($hl)
{
if (!isset($this->supportedLanguage[$hl])) {
$hl = self::DEFAULT_LANGUAGE;
}
$this->languge = $hl;
return $this;
}
/**
* Return the browser default language
*
* @return string
*/
public function getLanauge()
{
return $this->languge;
}
/**
* Return the default langauge name
*
* @return string
*/
public function getLanguageName()
{
return $this->supportedLanguage[$this->languge];
}
/**
* Return the supported language list of application
*
* @return array
*/
public function getSupportedLanguage()
{
return $this->supportedLanguage;
}
/**
* Return the language instance
*
* @staticvar null $instance
* @return \self
*/
static public function getInstance()
{
static $instance = null;
if (!$instance) {
$instance = new self;
}
return $instance;
}
}
Usage
use utility\i18n\Language;
$language = Language::getInstance();
echo $language->getLanguageName();
2/18/2014
1/10/2014
difference between strtr and str_replace in php
strtr and str_replace may replace one string with other string or multiple strings.
But they have little difference. You should take care of using them. Now I give some difference between them.
strtr usage
string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )
str_replace usage
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
1. with two strings
$string = "1.10.0101";
echo strtr($string, '01', 'a'), '
'; // only replace 0 with a
echo str_replace('01', 'a', $string), '
'; //only replace 01 with a
output
1.1a.a1a1
1.10.aa
2. with array
$string = "1.10.0101";
echo strtr($string, array("1" => "10", "10" => "b")), '
'; //first replace 10 with b, then replace 1 with 10, but it will not replace the newly replaced value
echo str_replace(array("1", "10"), array("a", "b"), $string); // first replace 1 with a, then based on newly replaced string, replace 10 with b
output
10.b.0b10
a.a0.0a0a
3. str_replace can replace more string with one same string
$string = "1.10.0101";
echo strtr($string, array("1" => "x", "10" => "x")), '
';
echo str_replace(array("1", "10"), 'x', $string), '
';
output
x.x.0xx
x.x0.0x0x
But they have little difference. You should take care of using them. Now I give some difference between them.
strtr usage
string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )
str_replace usage
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
1. with two strings
$string = "1.10.0101";
echo strtr($string, '01', 'a'), '
'; // only replace 0 with a
echo str_replace('01', 'a', $string), '
'; //only replace 01 with a
output
1.1a.a1a1
1.10.aa
2. with array
$string = "1.10.0101";
echo strtr($string, array("1" => "10", "10" => "b")), '
'; //first replace 10 with b, then replace 1 with 10, but it will not replace the newly replaced value
echo str_replace(array("1", "10"), array("a", "b"), $string); // first replace 1 with a, then based on newly replaced string, replace 10 with b
output
10.b.0b10
a.a0.0a0a
3. str_replace can replace more string with one same string
$string = "1.10.0101";
echo strtr($string, array("1" => "x", "10" => "x")), '
';
echo str_replace(array("1", "10"), 'x', $string), '
';
output
x.x.0xx
x.x0.0x0x
1/09/2014
Generating Random Passwords Class with PHP
You may create one random string or strong random password by using the following php class at will.
/**
* Description of RandomString
*
* @package
*/
class RandomString
{
/**
*
* @param int $length
* @return string
*/
static public function getRandom($length)
{
$randomData = base64_encode(file_get_contents('/dev/urandom', false, null, 0, $length) . uniqid(mt_rand(), true));
return substr(strtr($randomData, array('/' => '', '=' => '', '+' => '')), 0, $length);
}
}
/**
* Description of RandomString
*
* @package
*/
class RandomString
{
/**
*
* @param int $length
* @return string
*/
static public function getRandom($length)
{
$randomData = base64_encode(file_get_contents('/dev/urandom', false, null, 0, $length) . uniqid(mt_rand(), true));
return substr(strtr($randomData, array('/' => '', '=' => '', '+' => '')), 0, $length);
}
}
Subscribe to:
Posts (Atom)