Home >Backend Development >PHP Tutorial >How to use session in php WeChat public development platform

How to use session in php WeChat public development platform

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 09:13:401517browse

Sessions are stored on the server side, so to distinguish each user's session, you need to use the client's cookie. The WeChat server does not send cookies to the developer server, so cookie-based sessions cannot be used.

But as long as a unique session_id is set for each user, the same effect can be achieved.

Everyone’s WeChat ID is unique, so we can use WeChat ID as the user’s session_id, or we can use it after md5 encryption.

Set ToUserName as session_id as follows

  $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
  if(!empty($postStr)){
      $msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
      $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];  if(!empty($postStr)){        
      $msg = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
      //设置session_id
      session_id($msg['ToUserName']);
      session_start();
  }

The above introduces how to use session on the PHP WeChat public development platform, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn