Essentially I want to grab some data from a web page that only a logged in user can see i.e. Facebook analytics and Page insights.
If I query the specific page and try to grab it normally, it doesn't work.
Is there any way to do this?
Essentially I want to grab some data from a web page that only a logged in user can see i.e. Facebook analytics and Page insights.
If I query the specific page and try to grab it normally, it doesn't work.
Is there any way to do this?
Use CURL and cookie session to login to the page remotely
using these options:
$url = 'https://somewhere.com';
$post['user'] = 'myuser';
$post['pass'] = 'mypass';
$ch = curl_init( );
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_COOKIESESSION, true );
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt' );
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt' );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, count( $post ) );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/32.0.1700.107 Chrome/32.0.1700.107 Safari/537.36');
echo $result = curl_exec($ch); // Outputs HTML response from url
*Take note that posts name vary from the site your trying to login.
I have used this successfully.
$context = stream_context_create(array(
'http' => array('header' => "Authorization: Basic " . base64_encode("$username:$password"))
));
$data = file_get_contents($url, false, $context);