Evergreen Posted October 15, 2012 Share Posted October 15, 2012 Hello guys, it's my first post here.... 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. Quote Link to comment https://forums.phpfreaks.com/topic/269507-curl-problem/ Share on other sites More sharing options...
trq Posted October 16, 2012 Share Posted October 16, 2012 Not sure about your issue,b ut, none of the variables you have declared at the top of your script are available to the functions. Functions have there own scope. Quote Link to comment https://forums.phpfreaks.com/topic/269507-curl-problem/#findComment-1385424 Share on other sites More sharing options...
Evergreen Posted October 16, 2012 Author Share Posted October 16, 2012 I corrected that a few minutes ago after some debug and placed the variables at the right places. Still, problem not solved, nothing changes, does the same thing Quote Link to comment https://forums.phpfreaks.com/topic/269507-curl-problem/#findComment-1385429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.