CURL cookie value

I am trying to download music files from this site: looperman.com. I logged in as a user and I am trying to load loops using cURL. When you visit looperman.com, there are several cookies, but as an exception, I notice that the only thing required for the server to see that you are logged in is called "loopermanlooperman".

I grabbed the value of this cookie and set it as a variable. Then I submit it to the site as follows:

$sessid = 'somehashedvaluehere'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: loopermanlooperman=$sessid;")); curl_setopt($ch, CURLOPT_URL, "http://www.looperman.com/loops/detail/$pageID"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); echo $response; 

When I repeat the answer, I see that the cookie has not been set, and the site still sees that I have not logged in. What am I doing wrong? Looperman is built using CodeIgniter. I wonder if they have any protection to prevent the installation of such files?

////// UPDATE

I tried COOKIE_JAR and CURLOPT_COOKIE. The cookies are still not set. I found this script from another Stack Overflow column, which seems to have delivered me most of the way, but still the cookies are set. There he is:

 $loginUrl = 'http://www.looperman.com/account/login/'; $loginFields = array('user_email' => ' login@site.com ', 'user_password' => 'password'); getUrl($loginUrl, 'post', $loginFields); //now you're logged in and a session cookie was generated $remote_page_content = getUrl('http://www.looperman.com/loops/detail/200'); echo $remote_page_content; function getUrl($url, $method='', $vars='') { $ch = curl_init(); if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'D:\wamp2\www\sandbox\cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'D:\wamp2\www\sandbox\cookie.txt'); $buffer = curl_exec($ch); curl_close($ch); return $buffer; } 

When this returns, the contents of the file D: \ wamp2 \ www \ sandbox \ cookie.txt:

  Netscape HTTP Cookie File
 http://curl.haxx.se/rfc/cookie_spec.html
 This file was generated by libcurl!  Edit at your own risk.

 .looperman.com TRUE / FALSE 1329245288 loopermancspr 147f3f08a0b50f7aa527789e360abbc8
 .looperman.com TRUE / FALSE 1328467688 loopermanlooperman rX1UOdqyPEKkZ7HT0x8dSLk7g9yf5sSmg% 2B7zj66hLM9LSmS1z4nqFO2zkEkqsUqKEwNMvEiExqSKoU2% ​​2BfVsxlf3C9VyucMWt41TJVDtElUUIQrZxv0BmwZYP6JCJrY7wcT1% 2FO7kKxRu8YI97YD% 2BWdxX3jnWu2Zme9jg% 2FMggp3% 2Be% 2BY% 2FFiAorh36FR1zTbSY66VJVj7268WgMy6KNdJ1DxieypwaMb2HYGpBMsQRxcI6RawnOIEdjbaPKYuf8hVy40

But looperman still does not see me logged in :(

+6
source share
1 answer

You must use CURLOPT_COOKIE not CURLOPT_HTTPHEADER to set the cookie values ​​sent in the request.

 curl_setopt($ch, CURLOPT_COOKIE, "loopermanlooperman=$sessid") 

CURLOPT_COOKIE

The contents of the cookie: header that will be used in the HTTP request. Note that multiple cookies are separated by a semicolon and then a space (for example, "fruit = apple; color = red")

http://www.php.net/manual/en/function.curl-setopt.php/

This makes CURL a cookie . Try requesting a script that displays the contents of the headers as follows;

 <?php echo "Your cookies \n"; print_r( $_COOKIE); ?> 

Perhaps the site is checking the referral or host in your title. You can always try to view the requests made in the browser (in chrome go Spanner β†’ Tools β†’ Developer Tool β†’ Network, now request a page and click on the request in the list. All headers should show)

+11
source

Source: https://habr.com/ru/post/907657/


All Articles