php - Getting remote file contents after login with cURL -
php - Getting remote file contents after login with cURL -
as title suggest, i'm trying content of (several) pages on site requires login. legitimate login , have access content - nil shady's going on.
i've searched , found several posters attempting same thing - nil i've found has helped specific issue.
i've tried several variations - adding various options followlocation (set true, tried set false); increasing timeout; setting both cookiejar , cookiefile; calling curl_close after login, new curl_init after (before loading target file); using traditional php methods grab file (file_get_contents, etc); explicitly creating cookie file , setting writable; tried , without referer; tried changing referer; tried both http , https protocols; tried calling curl_close 1 time first forcefulness cookie written, running script block 1 time again afterward; etc... no luck.
below snapshot of code beingness used (just trying 1 file now).
any suggestions appreciated.
$e = curl_init(); curl_setopt($e, curlopt_url, 'https://www.some-site.com/login.php'); curl_setopt($e, curlopt_post, 1); curl_setopt($e, curlopt_postfields, 'username=bob&password=1234'); curl_setopt($e, curlopt_cookiejar, 'cookie.txt'); curl_setopt($e, curlopt_referer, 'https://www.some-site.com'); curl_setopt($e, curlopt_returntransfer, 1); curl_exec($e); curl_setopt($e, curlopt_url, 'https://www.some-site.com/posts.php?id=1'); $content = curl_exec($e); print htmlentities($content); curl_close($e);
there no actual error - curl working should, $content set "you're not signed in... please login now..." page.
after logging in via browser (fx, chrome, safari, ie), each post can accessed (again, through browser) without issue.
i'm stumped.
tyia suggestions - lmk if additional info helpful.
this i'm using page content after logged site.
$login_url = 'http://www.examplesite.com/php/login.php'; //these post info username , password $post_data = 'loginuser=smith&loginpass=sh20147'; //create curl object $ch = curl_init(); //set useragent $agent = $_server["http_user_agent"]; curl_setopt($ch, curlopt_useragent, $agent); //set url curl_setopt($ch, curlopt_url, $login_url ); //this post query curl_setopt($ch, curlopt_post, 1 ); //set post info curl_setopt($ch, curlopt_postfields, $post_data); //we want content after query curl_setopt($ch, curlopt_returntransfer, 1); //follow location redirects curl_setopt($ch, curlopt_followlocation, 1); /* set cookie storing files cookie files necessary since logging , session info needs saved */ curl_setopt($ch, curlopt_cookiejar, 'cookie.txt'); curl_setopt($ch, curlopt_cookiefile, 'cookie.txt'); //execute action login $postresult = curl_exec($ch); print_r($postresult);
after logged, logged page or specific page contents following.
$url = 'http://www.examplesite.com/members/home.php'; curl_setopt_array( $ch, array( curlopt_url => $url , curlopt_returntransfer => true )); $output = curl_exec($ch); echo $output;
more details
php curl
Comments
Post a Comment