简体   繁体   中英

PHP CURL Login with cookie

I have a chat service that i would like to make an announcement bot that runs on cron to post daily updates to this chat. The url is http://www6.cbox.ws/box/?boxid=524970&boxtag=7xpsk7&sec=form I have tried various curl examples online but none seem to get the job done. My latest attempt which was a failure.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www6.cbox.ws/box/?boxid=&boxtag=&sec=profile&n=andysmith&k=0000000000000000000000000000000000000000");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www6.cbox.ws/box/?boxid=&boxtag=&sec=profile&n=andysmith&logpword=iloveJD');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cbox.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cbox.txt');
curl_exec($ch);
curl_close($ch);

I just need it to login and post a message.

try with

$result=curl_exec($ch);
//print $result;
if($result === false)
{
    echo '<br/>Curl error: '.curl_error($ch);
    curl_close($ch);
    exit;           
}

and see the error

Note: if ur setting 'CURLOPT_REFERER' , u need to set

 curl_setopt($ch, CURLOPT_HEADER, true);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM