Session operation of Php-redis

Source: Internet
Author: User

This article introduces the content is about Php-redis session operation, has certain reference value, now shares to everybody, has the need friend can refer to

Configure PHP


First configure PHP parameters, the following 2 methods

Method 1:

Modify the php.ini file directly

Session.save_handler = Redissession.save_path = "tcp://127.0.0.1:6379"

Method 2:

Add the following to the header of the code page:

Ini_set ("Session.save_handler", "Redis"), Ini_set ("Session.save_path", "tcp://127.0.0.1:6379");

Note: If redis.conf the password is set in the configuration file Requirepass,save_path need to write this tcp://127.0.0.1:6379?auth=authpwd , otherwise can not error and will error

Page testing

<?php//ini_set ("Session.save_handler", "Redis"),//ini_set ("Session.save_path", "TCP ://127.0.0.1:6379 "); Session_Start ();//Deposit session$_session[' class '] = Array (' name ' = ' = ' alicelock ', ' num ' = 21); /Connection Redis$redis = new Redis (), $redis->connect (' 127.0.0.1 ', 6379);//Check Session_idecho ' session_id: '. SESSION_ID (). ' <br/> ';//redis deposited session (Redis is stored as a string as a key, session_id) echo ' redis_session: '. $redis->get (' phpredis_session: '. session_id ()). ' <br/> ';//php gets the session value Echo ' Php_session: '. Json_encode ($_session[' class '); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.