jquery操作cookie插件的使用

简单的插件

<script type="text/javascript">
 /*
 Create a cookie with the given name and value and other optional parameters.

 @example $.cookie('the_cookie', 'the_value');
 @desc Set the value of a cookie.
 @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
 @desc Create a cookie with all available options.
 @example $.cookie('the_cookie', 'the_value');
 @desc Create a session cookie.
 @example $.cookie('the_cookie', null);
 @desc Delete a cookie by passing null as value.

 @param String name The name of the cookie.
 @param String value The value of the cookie.
 @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
                             If set to null or omitted, the cookie will be a session cookie and will not be retained
                             when the the browser exits.
 @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
                        require a secure protocol (like HTTPS).
 @type undefined

 @name $.cookie
 @cat Plugins/Cookie
 @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

</script>

//jQuery获取cookie操作
$.cookie('name');

//jQuery cookie赋值操作
$.cookie('name','value');

//其他参数
$.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'phpff.com', secure: true});

还有功能更强大的插件,具体参考以下链接
https://github.com/carhartl/jquery-cookie
http://plugins.jquery.com/cookie/

Linux系统bash严重安全漏洞CVE-2014-6271的检测及修复方法

    9月25日消息,继“心脏流血”漏洞之后,安全研究专家又发现了一个危险级别为“毁灭级”(catastrophic)的漏洞,开源软件公司Red Hat在一份报告中称,在Linux系统中广泛使用的Bash软件漏洞有可能让黑客利用攻击一切连入互联网的设备。

该漏洞编号为CVE-2014-6271,主要存在于bash 1.14 – 4.3版本中,受影响的linux系统包括:Red Hat企业Linux (versions 4 ~7) 、Fedora distribution、CentOS (versions 5 ~7)、Ubuntu 10.04 LTS,12.04 LTS和14.04 LTS、Debian等。

 受影响的软件及系统:GNU Bash <= 4.3。

GNU Bash 4.3及之前版本在处理某些构造的环境变量时存在安全漏洞,向环境变量值内的函数定义后添加多余的字符串会触发此漏洞,攻击者可利用此漏洞改变或绕过环境限制,以执行shell命令。 漏洞可以直接在Bash支持的Web CGI环境下远程执行任意命令!一些路由器、堡垒机、VPN等网络设备也可能会受到影响.当cgi程序里需要创建子进程,且环境变量可控时,攻击者可以通过useragent,querystring等http特性构造恶意攻击代码进行远程攻击,可能直接导致服务器被恶意控制,从而导致数据存在泄露的风险。

美国国土安全部下属的美国电脑紧急响应团队(以下简称“US-CERT”)发出警告称,这一漏洞可能影响基于Unix的操作系统,包括Linux和Mac OS X。

    漏洞详情页面:http://seclists.org/oss-sec/2014/q3/650

    漏洞级别:非常严重

    RedHat官方提供漏洞详情:

    A flaw was found in the way Bash evaluated certain specially crafted environment variables. An attacker could use this flaw to override or bypass environment restrictions to execute shell commands. Certain services and applications allow remote unauthenticated attackers to provide environment variables, allowing them to exploit this issue.

RedHat官方提供的检测方式:

登录终端,运行如下命令:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

如果返回以下内容:表示存在次漏洞,则请尽快升级。
vulnerable this is a test
    
vulnerable
this is a test

目前官方已经提供了升级包请执行如下命令进行升级处理:
yum update -y bash

升级后,再一次执行前面的命令进行检测,若出现如下信息,则表示已修复:

而Ubuntu 用户则可以通过如下命令升级bash:

apt-get update apt-get install bash

其他Linux发行版,没有在线安装功能的,请使用以下脚本编译安装bash漏洞补丁:

#!/bin/bash cd /usr/local/src wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz tar zxf bash-4.3.tar.gz ; cd bash-4.3 wget -r -nd -np http://ftp.gnu.org/gnu/bash/bash-4.3-patches/ for BP in `ls bash43-*|grep -v sig`; do patch -p0 < $BP; done ./configure make && make install
    
#!/bin/bash
cd /usr/local/src
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
tar zxf bash-4.3.tar.gz ; cd bash-4.3
wget -r -nd -np http://ftp.gnu.org/gnu/bash/bash-4.3-patches/
for BP in `ls bash43-*|grep -v sig`; do patch -p0 < $BP; done
./configure
make && make install

漏洞是否修复成功的检测方法与前文一样。另外,有人提到升级后是否需要重启服务器?其实是不需要的,只要通过漏洞检测即可。当然,你要不放心,重启下也是可以的。。。

此次漏洞很严重,请看到此消息的朋友互相宣传扩散,谨防此漏洞带来任何损失。

php memcache 封装类

<?php
/*
 php memcache 封装类
*/
class new_memcache {

	private $memcache = null;

	public function __construct() {
		$this->memcache = new Memcache;
		$this->memcache->connect('localhost', 11211);
	}

	public function memcache() {
		$this->__construct();
	}

	public function get($name) {
		$value = $this->memcache->get($name);
		return $value;
	}

	public function set($name, $value, $ttl = 0, $ext1='', $ext2='') {
		return $this->memcache->set($name, $value, MEMCACHE_COMPRESSED, $ttl);
	}

	public function delete($name) {
		return $this->memcache->delete($name);
	}

	public function flush() {
		return $this->memcache->flush();
	}
	
	public function close() {
       
		return $this->memcache->close();
	}
	   
	public function increment($name , $value) {

		return $this->memcache->increment($name, $vlaue);
	}


	public function decrement($name , $value) {

		return $this->memcache->decrement($name, $vlaue);
	}


	public function getExtendedStats() {

		return $this->memcache->getExtendedStats();
	}


	public function getStats() {

		return $this->memcache->getStats();
	}
}
?>