I am having problems with curl, i am trying to login to torrentbytes.net and download a .torrent file
i dump the contents of the curl_exec ($ch);
and all i get is 1
also i do not see any information in the cookiefile
any help?
i know curl works on my website, so thats not the problem....
thx in advance
<?php
function stripbad($string) {
$string = strtolower($string);
$string = str_replace(';', '', $string);
$string = stripslashes($string);
$string = str_replace('%', '', $string);
$string = str_replace('"', '', $string);
$string = str_replace("'", '', $string);
$string = str_replace(" ", '', $string);
return $string;
}
function stripbad2($string) {
$string = strtolower($string);
$string = str_replace(';', '', $string);
$string = str_replace('"', '', $string);
$string = str_replace("'", '', $string);
return $string;
}
if ($action == "submit"){
$username = stripbad($_POST['username']);
$password = stripbad($_POST['password']);
$torrent = stripbad2($_POST['torrent']);
$findme = '&';
$pos = strpos($torrent, $findme);
if ($pos == true) {
$torrent = substr($torrent, 0, $pos);
echo "The string '$findme' was found in the string '$torrent'";
echo " and exists at position $pos<br>";
}
$torr = substr($torrent, 0, 10);
if ($torr == 'http://www'){
$torrent = substr($torrent, 44);
}
if ($torr == 'http://tor'){
$torrent = substr($torrent, 40);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
curl_setopt($ch, CURLOPT_URL,"http://www.torrentbytes.net/takelogin.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) //Gecko/20061010 Firefox/2.0");
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=" . $username . "&password=" . $password);
curl_setopt($ch, CURLOPT_REFERER, "http://www.torrentbytes.net/login.php");
ob_start(); // prevent any output
$buf = curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
unset($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) //Gecko/20061010 Firefox/2.0");
curl_setopt($ch, CURLOPT_REFERER, "http://www.torrentbytes.net/browse.php");
curl_setopt($ch, CURLOPT_URL,"http://www.torrentbytes.net/download.php?id=" + $torrent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$buf2 = curl_exec ($ch);
curl_close ($ch);
$filename = "test.torrent";
$fp= fopen($filename, 'a');
fwrite ($fp, $buf2);
fclose($fp);
echo '<textarea rows=30 cols=40>' . $buf . '</textarea><br>';
echo '<textarea rows=20 cols=40>' . $buf2 . '</textarea><br>';
$buf2 = "";
}else{
include ("form.php");
}
?>