Hello,
I'm trying to automate downloading from turbobit.net through php, i login successfully and get all the cookies. then when i try to intiate another connection to download a file i get these headers back

HTTP/1.1 200 OK Date: Thu, 26 Jul 2012 17:44:02 GMT Content-Type: text / html; charset = UTF-8 Transfer-Encoding: chunked Connection: keep-alive Server: Apache/2.2.17 (FreeBSD ) X-Powered-By: PHP/5.3.6 Set-Cookie: kohanasession = 6cadbdd3a672521dc2d5300ffcd171% 7E; expires = Wed, 25-Jul-2012 17:44:02 GMT; path = / Set-Cookie: kohanasession = 59356c3ccc6cc6fffd76e7; expires = Thu, 26-Jul-2012 20:44:02 GMT; path = / Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check = 0, pre-check = 0 Pragma: no-cache Set-Cookie: kohanasession = 7c638f49b6a12c776d472f21ca3b7% 7E594a3ab17bce356c3ccc6cc6fffd76e7; expires = Thu, 26-Jul-2012 20:44:02 GMT; path = / Set-Cookie: sid = 8116a48a58d5f88cc6cd9722309bc1ce99% 7E; expires = Wed, 25-Jul-2012 17:44:02 GMT; path = / Set-Cookie: compid = 1be9124912615302d539ace729f2ec% 7E; expires = Wed, 25-Jul-2012 17:44:02 GMT; path = / Set-Cookie: compid = f06a60e996****e6cc619bbfb9fc40% 7E8222534783D7BED9D0A8EC1FD5A; expires = Fri, 26-Jul-2013 17:44:02 GMT; path = / Set-Cookie: user_isloggedin = deleted; expires = Wed, 27-Jul-2011 17:44: 01 GMT; path = / Set-Cookie: user_lang = ru; path = / Set-Cookie: refuid = 10a524e67c7a7b7b07d571eda4f61eacbddddf3e% 7EE2183B36E74D4E97F5D8AB5D280571BE; expires = Fri, 26-Jul-2013 17:44:02 GMT; path = /

if you noticed
Set-Cookie: user_isloggedin = deleted; expires = Wed, 27-Jul-2011 17:44: 01 GMT

while when i login its set to 1, but when i try to get the download link its rejecting, anyone can tell me what are cause of this. and did anyone do something like before

thanks

Dani AI

Generated

A short, practical diagnosis and checklist based on the thread and the code shown by .

The server is explicitly clearing the login cookie (you see a cookie set to "deleted"). The most common reasons for that are: the second request is not the same kind of request the server expects (for example a HEAD instead of a GET), cookies are not actually being read back from the cookie file, or the request is missing a required token/header (referer, correct host/scheme, CSRF token, etc.). Framework session cookies (the kohanasession names in the response) mean the site expects a very specific request flow — deviating from that will trigger a logout.

Quick checks and fixes to try in this order:

  • Stop sending a HEAD-only request. In the posted call the "body" flag was set so cURL does not fetch the body; make the request a normal GET so the site can run its usual page logic.
  • Confirm the cookie file actually contains the session cookies after login (open the cookie file and inspect it). Ensure you use the same host and scheme (http vs https) when logging in and when requesting the download.
  • Use both cookie jar and cookie file consistently (let cURL save cookies on login and read them on subsequent requests), and use absolute paths to the cookie file to avoid path errors.
  • Turn on verbose logging for curl to see the full request/response headers and redirects; compare what the browser sends when a download works versus what your script sends (user-agent, referer, cookies, and any hidden form/token).

If those do not fix it, the site may require a JS-generated token, captcha or other anti-bot checks that cannot be bypassed by a simple curl script. Also note automation may violate the site terms of service. asked for options earlier — the steps above focus on the most likely misconfiguration (HEAD request / cookie handling) before trying alternate libraries or classes such as the one linked.

Recommended Answers

All 4 Replies

Show the curl options you are using.

function DMcURL($url, $cookie = false, $header = false, $body = false, $ref = false, $post = false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

if($header != false) curl_setopt($ch, CURLOPT_HEADER, $header);
if($body != false) curl_setopt($ch, CURLOPT_NOBODY, $body);
if($ref != false) curl_setopt($ch, CURLOPT_REFERER, $ref);

if($post != false) 
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}

if ($cookie != false) curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/'.$cookie);

$content = curl_exec($ch);
return $content;
}


function DMLogin($url, $post = false, $ref = false, $cookie = false)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

if($ref != false) curl_setopt($ch, CURLOPT_REFERER, $ref);

if($post != false) 
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}

if ($cookie != false) curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/'.$cookie);


if ($content = curl_exec($ch))  return $content;
else return false;
}


//this one works fine, i get the correct cookies
$postfields = 'user[login]=xxx&user[pass]=xxx&user[memory]=on&user[submit]=Login';
$process = DMLogin('http://turbobit.net/user/login', $postfields, false, 'turbobit1');


$e = DMcURL($link, 'turbobit1', 1, 1, $link);
echo $e;
//here is where i get the strange headers

I don't spot any apparent issues. Hope someone else can help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.