Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.