Curl remote login and remote posting questions www. czhi-fi.combbsxp Forum is a bbsxp forum system is version 5.15. I use snoopy to remotely log on and post a message. However, curl cannot be used for remote logon, not to mention remote posting. I would like to use curl for simulated logon. please kindly advise me !! Thank you !! (Login address: www. czhi-fi.combbsx curl remote login and remote posting problems)
Http://www.czhi-fi.com/bbsxp/ Forum is a bbsxp forum system with version 5.15.
I use snoopy to remotely log on and post a message. However, curl cannot be used for remote logon, not to mention remote posting.
I would like to use curl for simulated logon. please kindly advise me !! Thank you !!
Note:
Address: http://www.czhi-fi.com/bbsxp/login.asp
Username: mytest
Password: 111111
First, publish the code that I successfully used snoopy to remotely log on and post to the public:
PHP code
$ Url =" http://www.czhi-fi.com/bbsxp/ "; // Forum address $ url1 =" http://www.czhi-fi.com/bbsxp/ Default. asp "; // source address $ url2 =" http://www.czhi-fi.com/bbsxp/ Login. asp "; // logon submission judgment page $ posts = array (); $ posts ['menu '] = 'add'; $ posts ['URL'] = $ url1; $ posts ['username'] = 'mytest'; $ posts ['userpass'] = '000000'; include ("Snoopy. class. php "); $ snoopy = new Snoopy; $ snoopy-> submit ($ url2, $ posts ); // simulate the submission by the browser and obtain the returned results./* The Post is shown below */$ url3 =" http://www.czhi-fi.com/bbsxp/ Newtopic. asp "; // post submission page. $ Topic = 'Classic Joke: divorce '; // Title $ content = 'zhangda: "The child is his mother. Can we divorce ?" Wife: "We have never had a fight. why divorce ?" Husband: "I mean, I will marry you again after divorce ." Wife: "Ah, are you crazy today ?" Husband: "No! You see, in the past few years, young people have been married and all my pockets have been hollowed out. if we don't get married again, how can we get these practices back? '; $ Posts = array (); $ posts ['forumid'] = '16'; // Plate id. this is the irrigation plate $ posts ['topic'] = $ topic; // Title $ posts ['content'] = $ content; // content $ snoopy-> submit ($ url3, $ posts ); // simulate a browser submission and obtain the returned results. // print_r ($ snoopy-> results); $ content = $ snoopy-> results ;// http://www.czhi-fi.com/bbsxp/ ShowPost. asp? Id = 3148 // ShowForum. asp? Forumid = 16if (preg_match ("/\" (\ d +) \ ", \" [^ \ r \ n \ "] *? \ ", \" [^ \ R \ n \ "] *? \ ", \" Mytest \ "/is", $ content, $ matches) {if (! Empty ($ matches [1]) {$ out = $ url. "ShowPost. asp? Id = ". $ matches [1];} else {$ out = "the address of the Last Post has not been collected. check whether there are any new posts in this section ";}} else {$ out = "posting may fail. check whether there are any new posts in this section";} echo "". $ out. "";
*************************************
The following is my curl logon code. this code cannot be used for remote logon. please kindly advise!
PHP code
$ Login_url = "http://www.czhi-fi.com/bbsxp/login.asp"; // logon page address $ source_url = "http://www.czhi-fi.com/bbsxp/default.asp"; // source page address $ post_fields = array (); // the following two fixed values: $ post_fields ['menu '] = 'add'; $ post_fields ['URL'] = 'http: // response = "mytest "; $ post_fields ['userpass'] = "111111"; $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_REFERER, $ source_url); curl_setopt ($ ch, CURLOPT_USERAGENT, $ _ SERVER ['http _ USER_AGENT ']); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // allow automatic jump to $ contents = curl_exec ($ ch ); curl_close ($ ch); echo $ contents;
I would like to use curl for simulated logon. please kindly advise me !! Thank you !!
------ Solution --------------------
Obtain the cookie (set-Cookie in the http response header) and report it to the past (cookie in the http request header ).
PHP code
$ Login_url = "http://www.czhi-fi.com/bbsxp/login.asp"; // logon page address $ source_url = "http://www.czhi-fi.com/bbsxp/default.asp"; // source page address $ post_fields = array (); // the following two fixed values/* $ post_fields ['menu '] = 'add'; $ post_fields ['URL'] = 'http: // response = "mytest "; $ post_fields ['userpass'] = "111111"; */$ cookie = "cookie.txt"; $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_REFERER, $ source_url); curl_setopt ($ ch, CURLOPT_USERAGENT, $ _ SERVER ['http _ USER_AGENT ']); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, expires, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie); curl_setopt ($ ch, CURLOPT_POSTFIELDS, 'username = mytest & userpass = 111111 & menu = add & url = http://www.czhi-fi.com/bbsxp/Default.asp'); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1 ); // allow automatic jump $ contents = curl_exec ($ ch); curl_close ($ ch); echo $ contents;