Curl remote logon and remote posting

Source: Internet
Author: User
Curl remote logon and remote posting problems http://www.czhi-fi.com/bbsxp/forum is a bbsxpforum system with 5.15.pdf. 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 !! Notes: curl remote logon and remote posting
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;

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.