glenelkins Posted January 18, 2010 Share Posted January 18, 2010 Hi I have come accross the following code that allows me to grab a web page of a site that requires login first. Though it doesnt seem to submit the login form or return any session details: <?php ini_set ( 'safe_mode', '0' ); $_loginUrl = 'http://loginurl/'; $_loginFields = array ( 'username' => 'username', 'password' => 'password' ); $_remotePageUrl = 'http://pageafterlogin/'; $_login = getUrl ( $_loginUrl, 'post', $_loginFields ); $_remotePage = getUrl ( $_remotePageUrl ); echo $_login; echo $_remotePage; function getUrl ( $url, $method='', $vars = '' ) { $ch = curl_init(); if ( $method = 'post' ) { curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $vars ); } curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt ( $ch, CURLOPT_COOKIEJAR, 'cookies/cookies.txt' ); curl_setopt ( $ch, CURLOPT_COOKIEFILE, 'cookies/cookies.txt' ); $buffer = curl_exec ( $ch ); curl_close ($ch ); return $buffer; } ?> I can't actually see anything wrong with it Link to comment https://forums.phpfreaks.com/topic/188879-displaying-web-page-after-login-with-curl/ Share on other sites More sharing options...
trq Posted January 18, 2010 Share Posted January 18, 2010 Your question being? Link to comment https://forums.phpfreaks.com/topic/188879-displaying-web-page-after-login-with-curl/#findComment-997289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.