PhpQQ login session ['state'] cannot be found, how to deal with it-php Tutorial

Source: Internet
Author: User
Tags mysql host
PhpQQ login session [state] has been unable to find the virtual space for solving the easy-to-contact host (do not know whether it is related to this) using QQsdkphp for QQ login follow the steps to set config and session file end only one session. php code & lt ;? Php ** & nbsp; * PHPSDKforQQ login OpenAPI & nbsp; * php QQ login session ['state'] cannot be found
Virtual Space of the easy-to-contact host (I don't know if it is related to this)

Use qq sdk php for QQ login
Set the config and session files according to the steps.
There is only one end





// Session. php code


/**
* Php sdk for QQ login OpenAPI
*
* @ Version 1.2
* @ Author [email protected]
* @ Copyright©2011, Tencent Corporation. All rights reserved.
*/

/**
* @ Brief set session configuration
*/

/**
* Create table 'tbl _ session '(
* 'Session _ id' varchar (255) binary not null default '',
* 'Session _ expires' int (10) unsigned not null default '0 ',
* 'Session _ data' text,
* Primary key ('session _ id ')
*) ENGINE = MyISAM;
*/

Class Session
{
// Mysql host address
Const db_host = "localhost"; // The IP address must be specified by a third party.

// Database username
Const db_user = "ibrat"; // The user name must be specified by a third party.

// Database password
Const db_pwd = "ibrat"; // the password of the database must be specified by a third party.

// Database
Const db_name = "ibrat"; // A database must be specified by a third party.

// Database table
Const db_table = "ghb_session"; // a data table needs to be specified by a third party

// Mysql-handle
Private $ db_handle;

// Session-lifetime
Private $ lifeTime;

Function open ($ savePath, $ sessName)
{
// Get session-lifetime
$ This-> lifeTime = get_cfg_var ("session. gc_maxlifetime ");

// Open database-connection
$ Db_handle = @ mysql_connect (self: db_host, self: db_user, self: db_pwd );

$ DbSel = @ mysql_select_db (self: db_name, $ db_handle );

// Return success
If (! $ Db_handle |! $ DbSel)
Return false;

$ This-> db_handle = $ db_handle;
Return true;
}

Function close ()
{
$ This-> gc (ini_get ('session. gc_maxlifetime '));
// Close database-connection
Return @ mysql_close ($ this-> db_handle );
}

Function read ($ sessID)
{
// Fetch session-data
$ Res = @ mysql_query ("SELECT session_data AS d FROM". self: db_table ."
WHERE session_id = '$ sessID'
AND session_expires> ". time (), $ this-> db_handle );

// Return data or an empty string at failure
If ($ row = @ mysql_fetch_assoc ($ res ))
Return $ row ['D'];

Return "";
}

Function write ($ sessID, $ sessData)
{
// New session-expire-time
$ NewExp = time () + $ this-> lifeTime;

// Is a session with this id in the database?
$ Res = @ mysql_query ("SELECT * FROM". self: db_table ."
WHERE session_id = '$ sessID' ", $ this-> db_handle );

// If yes,
If (@ mysql_num_rows ($ res ))
{
//... Update session-data
@ Mysql_query ("UPDATE". self: db_table ."
SET session_expires = '$ newExp ',
Session_data = '$ sessdata'
WHERE session_id = '$ sessID' ", $ this-> db_handle );

// If something happened, return true
If (@ mysql_affected_rows ($ this-> db_handle ))
Return true;
}
Else // if no session-data was found,

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.