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_string = 'detail = addaction & a php simulates the post method to open the page
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.
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.