Php simulates the post mode to open the page. I log on to the background and want to simulate the post mode to jump to another page and process the data in the background. However, the prompt asking me to log on again is always displayed, I guess the $ _ SESSION value has been lost when I simulate the post method jump. How can this problem be solved? The code is as follows: $ post_stringdetailaddaction & amp; subva0 & amp; nametestadmin & php opens the page through post simulation
After logging on to the background, I want to simulate the use of post to jump to another page and process the data in the background. However, the prompt asking me to log on again is always displayed. I guess it is a simulated post jump, the $ _ SESSION value has been lost. How can this problem be solved?
The code is as follows:
$ Post_string = 'detail = addaction & subva = 0 & name = testadmin & password = 123456 & sex = 1'
$ Context = array (
'Http' => array (
'Method' => 'post ',
'Header' => 'Content-type: application/x-www-form-urlencoded \ r \ nUser-Agent: Jimmy \'s POST Example beta \ r \ nContent-length: '. strlen ($ post_string) + 8,
'Content' => 'mypost = '. $ post_string
)
);
$ Stream_context = stream_context_create ($ context );
$ Data = file_get_contents ("http: // xxxxxxxx/xxxx/main. php", false, $ stream_context );
Echo $ data;
------ Solution --------------------
1) first POST the data to the login screen
2) the returned result contains a Cookie: SessionID = xxxxxxxxxxxx.
3) retrieve the SessionID and then follow your POST method above
'Header' => 'Content-type: application/x-www-form-urlencoded \ r \ nUser-Agent: Jimmy \'s POST Example beta \ r \ nContent-length: '. strlen ($ post_string) + 8,
'Header' => 'cookie: SessionID = xxxxxxxxx; Content-type: application/x-www-form-urlencoded \ r \ nUser-Agent: jimmy \'s POST Example beta \ r \ nContent-length :'. strlen ($ post_string) + 8,
The Cookie format is not clear. the above is only Sample.