Session cannot be passed, files can be saved, but mysql cannot.

Source: Internet
Author: User
The session cannot be passed, files can be saved, and mysql cannot save the verification code in the session. when files is used to save the session, the user can read the verification code in the background $ _ SESSION ['captcha '] during registration. that is to say, the verification code can be passed normally. However, when the user uses mysql to save the session, the session can be properly stored (The session value of captcha can be seen in the database). On the page that generates the verification code, you can use $ _ SESSION ['captcha '] to read the value, however, after the user registers for another page in the background, the value cannot be read (that is to say, it cannot be passed). It was a long time ago. but now it turns out that it doesn't work. can anyone think of the reason?


Reply to discussion (solution)

If the session is saved in the database, the corresponding code must be loaded on each page that uses the session.
Have you done it?

This has a session detailed explanation can see the http://www.phpthinking.com/archives/318

If the session is saved in the database, the corresponding code must be loaded on each page that uses the session.
Have you done it?



Well, every time you use a session
If (! Isset ($ _ SESSION )){
Require_once _ DIR _. '/SessionHandler. php ';
New \ lib \ SessionHandler ();
}
The SessionHandler. php file contains the corresponding code, but the problem is that other pages cannot read the session value ~

To prevent unexpected situations
The program should unconditionally load SessionHandler. php
The instantiated object and session_start () should be carried out in SessionHandler. php.
You also use the namespace, so you need to check for new fault points.

To prevent unexpected situations
The program should unconditionally load SessionHandler. php
The instantiated object and session_start () should be carried out in SessionHandler. php.
You also use the namespace, so you need to check for new fault points.



Removing conditional references and namespace does not work.
Not to mention different pages, even the same page cannot be read, as shown below:
Error_log ($ _ SESSION ["captcha"]);
$ _ SESSION ["captcha"] = $ text;
In the first sentence error_log ($ _ SESSION ["captcha"]); in the $ _ SESSION ["captcha"], you want to read the value of captcha in the previous database, in this case, the database has a value but cannot read it. the error "PHP Notice: Undefined index: captcha" is displayed,
The session_read function in my SessionHandler class is as follows:
Function readSession ($ SID ){
$ Query = "select value from sessioninfo where sid =: sid ";
$ Stmt = $ this-> dbLink-> prepare ($ query );
$ Stmt-> bindParam (': sid', $ SID );
If ($ stmt-> execute ())
{
$ Value = $ stmt-> fetch (\ PDO: FETCH_ASSOC );
/* Error_log ('Sid: '. $ sid );*/
/* Error_log ('value: '. implode (', ', $ value ));*/
If (! Empty ($ value ))
{
Return $ value;
}
}
}
The $ value read from the code commented out above has a value. that is to say, php reads the value but does not deserialize it into the memory?


To prevent unexpected situations
The program should unconditionally load SessionHandler. php
The instantiated object and session_start () should be carried out in SessionHandler. php.
You also use the namespace, so you need to check for new fault points.



Removing conditional references and namespace does not work.
Not to mention different pages, even the same page cannot be read, as shown below:
Error_log ($ _ SESSION ["captcha"]);
$ _ SESSION ["captcha"] = $ text;
In the first sentence error_log ($ _ SESSION ["captcha"]); in the $ _ SESSION ["captcha"], you want to read the value of captcha in the previous database, in this case, the database has a value but cannot read it. the error "PHP Notice: Undefined index: captcha" is displayed,
The session_read function in my SessionHandler class is as follows:
Function readSession ($ SID ){
$ Query = "select value from sessioninfo where sid =: sid ";
$ Stmt = $ this-> dbLink-> prepare ($ query );
$ Stmt-> bindParam (': sid', $ SID );
If ($ stmt-> execute ())
{
$ Value = $ stmt-> fetch (\ PDO: FETCH_ASSOC );
/* Error_log ('Sid: '. $ sid );*/
/* Error_log ('value: '. implode (', ', $ value ));*/
If (! Empty ($ value ))
{
Return $ value;
}
}
}
The $ value read from the code commented out above has a value. that is to say, php reads the value but does not deserialize it into the memory?



It turns out that the problem is here ~
Instead of returning $ value, return $ value ['value'];
Finally Solved ~ Thank you ~

This has a session detailed explanation can see the http://www.phpthinking.com/archives/318



This article is very detailed ~ Good article ~


This has a session detailed explanation can see the http://www.phpthinking.com/archives/318



This article is very detailed ~ Good article ~

Thank you for your support. I hope my personal blog can be a friend QQ 541578455.

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.