Session_id assignment is difficult,

Source: Internet
Author: User
The assignment of session_id encountered an inexplicable problem. in a hurry !!!! Both Page A and page B are in the same web root directory, and session_id must be passed because page A needs to use the curl post to page B and obtain the returned data, is considered another terminal by the server. The idea is as follows: on the page A. php, passing the current session_id assignment has some inexplicable problems. hurry !!!!
Both Page A and page B are in the same web root directory, and session_id must be passed because page A needs to use the curl post to page B and obtain the returned data, is considered another terminal by the server.
The idea is as follows: Page. php transmits the current session_id to page B. php (post method), page B. php uses session_id () to operate on the page. php and B. php shared session.
The following code is used:
Page A. php

/*
* Generate a verification code Image
* Author yuanjiang @ developer.2014
*/
Define ("IN_WD", true );
Require ('Des/init. php ');

$ Sessionid = session_id ();

$ Url = CLIENT_HOST. 'createcaptcha. php ';
$ KeyArr = array ('sessionid' => $ sessionid );

$ Captcha = $ Common-> file_post ($ url, $ keyArr );
Echo base64_encode ($ captcha); // base64 encoded image for client and web calls

?>

The following is page B, that is, the createCaptcha. php above.

/*
* Generate a verification code Image
* Author yuanjiang @ developer.2014
*/
Define ("IN_WD", true );
$ Sessionid = isset ($ _ POST ['sessionid'])? $ _ POST ['sessionid']: ''; // switch the session status based on the post sessionid
If (! Empty ($ sessionid ))
{
Session_id ($ sessionid); // The program will be stuck when this step is executed. it is correct when $ sessionid is not equal to session_id of page A. php
}
Session_start ();
Require ('Des/cls_captcha.php ');
$ Captcha = new Captcha;
$ Captcha-> generate_image (); // generate an image
?>

------ Solution --------------------
Page
$ Sessionid = session_id ();
Session_write_close (); // close the session
// Access B
Session_id ($ sessionid)
Session_start (); // re-open the session

The cause of program freezing is that the session temporary file opened by page A is exclusive and cannot be opened again before it is closed.

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.