Jump to content

Extract POST and GET results from a page with authentication/cookies


Exoskeletor

Recommended Posts

Hello guys, nice forum you have here, im a happy new member with a happy problem :)

I have this code to get the Post results of a page and it works. my problem is that it doesnt work in pages that require login and cookies. how i can alter it in order to use cookies? for example for this page http://www.zazopoulossa.gr/index.php i need to send username and password, get the cookie and then send a new post message with the cookie.

 

	$postdata = http_build_query(
   		 array(
        'keyword' => $code[$i]
    	 )
	);
	$opts = array('http' =>
    		array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    		)
	);
	$context  = stream_context_create($opts);
	$result = file_get_contents('http://www.zazopoulossa.gr/index.php', false, $context);

file_get_contents was not built for handling cookies etc. You should really look into curl as that is it's sole intention is fetching websites. It can handle cookies just fine and you will find plenty of examples of that at the manual and on google. Not to mention it will be at least 3x faster in retrieving the content over file_get_contents.

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.