开发者

How to store multiple cookies through PHP Curl

开发者 https://www.devze.com 2022-12-27 01:38 出处:网络
\'SOUP.IO\' is not providing any api. So Iam trying to use \'PHP Curl\' to login and submit data through PHP.

'SOUP.IO' is not providing any api. So Iam trying to use 'PHP Curl' to login and submit data through PHP.

Iam able to login the website successfully(through cUrl), but when I try to submit data through cUrl, it gives me error of 'invalid user'.

When I tried to analysed the code and website, I came to know that cUrl is getting values of only 1-2 cookies. Where as when I open the same page in FireFox, it shows me 6-7 cookies related to 'SOUP.IO'.

Can some one guide me how to get all these 7 cookies values.

Following cookies are getable by cUrl:

soup_session_id

Following cookies are shown in Firefox (not through cUrl):

__qca, __utma, __utmb, __utmc, __utmz

Following is my cUrl code:

<?php
session_start();

$cookie_file_path = getcwd()."/cookie/cookie.txt";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.soup.io');
curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_HEADER, TRUE);

curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);


curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 开发者_Go百科(.NET CLR 3.5.30729) FirePHP/0.4');


curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);


$result = curl_exec($ch);

curl_close($ch);


print_r($result);
?>

Can some one guide me in this regards

Thanks in advance


These extra "underscore" cookies seem like Google Analytics or similar tracking cookies, most likely set via Javascript. That's the reason they don't show up when using cURL. I'd venture the guess that they're not the problem.


A couple of things i noticed once i signup and went into the area. The domain all my action happens is "user.soup.io" and not "www.soup.io" , that could be the reason behind your invalid user error. Try to set the url to your own subdomain AFTER the login is complete and see how it goes. Also what data are you exactly trying to post?

This may not be relevant but soup.io doesnt seem to use HTTPS, so why use:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);


Here is my curl code which Iam trying to use for sending data to soup.io after suceesful login through cUrl

$storedata = array();
$storedata["post[title]"]               = 'Phoonk 2 (16th April 2010)';
$storedata["post[body]"]                = 'Ramgopal Varma\'s love for horror and supernatural continues. This time, in PHOONK 2, the team behind PHOONK promise more chills, more thrills and more screams. But what you get to hear at the end of the screening is a moan, since PHOONK 2 lacks the chills, thrills and screams that were the mainstay of its first part.';
$storedata["post[tags]"]                = 'Bollywood Movie, Indian movie';
$storedata["commit"]                    = 'Save';
$storedata["post[id]"]                  = '';
$storedata["post[type]"]                = 'PostRegular';
$storedata["post[parent_id]"]           = '';
$storedata["post[original_id]"]         = '';
$storedata["post[edited_after_repost]"] = '';
$store_post_str = '';
foreach($storedata as $key => $value){
    $store_post_str .= $key.'='.urlencode($value).'&';
}
$store_post_str = substr($store_post_str, 0, -1);

$ch2 = curl_init();

curl_setopt($ch2, CURLOPT_URL, 'http://loekit.soup.io/save');
curl_setopt($ch2, CURLOPT_VERBOSE, 1);

curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch2, CURLOPT_HEADER, TRUE);

curl_setopt($ch2, CURLOPT_ENCODING, 'gzip,deflate');

//curl_setopt($ch2, CURLOPT_COOKIEJAR, $cookie_file_path);
//curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_file_path);

curl_setopt($ch2, CURLOPT_REFERER, 'http://loekit.soup.io/');
curl_setopt($ch2, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729) FirePHP/0.4');
curl_setopt($ch2, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $store_post_str);
curl_setopt($ch2, CURLOPT_POST, TRUE);
0

精彩评论

暂无评论...
验证码 换一张
取 消