Reputation:
I am using curl to do three tasks. That is, login to my test site, go to the form where we input the text and get the hidden random session_id
, set the third curl request to post the message with the session_id recieved.
But here am able to perform only first two requests. The message is not posting.
index.php
$ch = curl_init();
$url = 'http://webforum.com';
include 'a.php';
$url = 'http://webforum.com/add_message.php';
include 'C.php';
preg_match_all('|name="session_id" value="(.*?)"|',$store,$tks);
$token = $tks[1][0];
$postf = 'session_id='.$token.'&add=mga&text=TAPPOUT&submit=Submit';
include 'c.php';
?>
c.php
$cookie_file_path="cookies.txt";
$agent="Nokia-Communicator-WWW-Browser/2.0 (Geos 3.0 Nokia-9000i)";
$headers[]="Accept: */*";
$headers[]="Connection: Keep-Alive";
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file_path);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_USERAGENT,$agent);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postf);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file_path);
$store = curl_exec($ch);
?>
Can anyone figure out the problem?
Upvotes: 0
Views: 90
Reputation: 157839
Why use such awkward and unreliable method as emulating a browser? what if there would be a captcha, or some JS, or whatever else obstacle?
You have to use a tool that is intended for your current task, not for something else.
You can use SOAP, RPC, XML, direct access to database, POLL instead of PUSH and many other methods each of which would be way more useful than this silly emulation. Of course it will require some programming on the server side but that's not going to be a problem.
Upvotes: 2