Jump to content

Curl Problem


Evergreen

Recommended Posts

Hello guys, it's my first post here.... :happy-04:

 

Here is the code I got for now(changed the domain and subdomain names):

<?php
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16";
$headers = "Expect:";
$postdata = "username=test&password=test&ref=".base64_encode(md5(time().".com"))."&session=s".md5(time());
$login="http://subdomain.mydomain.com/login.php";
$grab="http://subdomain.mydomain.com/index.php";
function login($url,$data){
   $fp = fopen("cookie.txt", "w");
   fclose($fp);
   $login = curl_init();
   curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
   curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
   curl_setopt($login, CURLOPT_TIMEOUT, 40000);
   curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($login, CURLOPT_URL, $url);
   curl_setopt($login, CURLOPT_USERAGENT, $agent);
   curl_setopt($login, CURLOPT_COOKIESESSION, true);
   curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
   curl_setopt($login, CURLOPT_POST, TRUE);
   curl_setopt($login, CURLOPT_POSTFIELDS, $data);
   ob_start();
   return curl_exec ($login);
   ob_end_clean();
   curl_close ($login);
unset($login);
}				 
function grab_page($site){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_USERAGENT, $agent);
   curl_setopt($ch, CURLOPT_TIMEOUT, 40000);
   curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
   curl_setopt($login, CURLOPT_COOKIESESSION, true);
   curl_setopt($ch, CURLOPT_URL, $site);
   ob_start();
   return curl_exec ($ch);
   ob_end_clean();
   curl_close ($ch);
}
function grab_subpage($site){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_USERAGENT, $agent);
   curl_setopt($ch, CURLOPT_TIMEOUT, 40000);
   curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
   curl_setopt($login, CURLOPT_COOKIESESSION, true);
   curl_setopt($ch, CURLOPT_URL, $site);
   ob_start();
   return curl_exec ($ch);
   ob_end_clean();
   curl_close ($ch);
}
function post_data($site,$data){
   $datapost = curl_init();
   curl_setopt($datapost, CURLOPT_URL, $site);
   curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
   curl_setopt($datapost, CURLOPT_HEADER, TRUE);
   curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($datapost, CURLOPT_USERAGENT, $agent);
   curl_setopt($datapost, CURLOPT_POST, TRUE);
   curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
   curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
   ob_start();
   return curl_exec ($datapost);
   ob_end_clean();
   curl_close ($datapost);
   unset($datapost);
}
login($login, $postdata);
echo grab_page($grab);
?>

 

OK , so ... this code works fine if i navigate any page from http://subdomain.mydomain.com/ but if i try to grab a page from http://anothersubdomain.mydomain.com/ it drops and shows me a white page. var_dump(grab_page($grab)); echoes me string(0) "" . I can't figure out what is the problem and why I can't access that page. I'm googling for a week now and tryied tons of metods and nothing worked, maybe you guys can help me...

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/269507-curl-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.