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.