Jump to content

Displaying Web Page After Login With curl


glenelkins

Recommended Posts

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

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.