Exoskeletor Posted July 13, 2011 Share Posted July 13, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/241885-extract-post-and-get-results-from-a-page-with-authenticationcookies/ Share on other sites More sharing options...
premiso Posted July 13, 2011 Share Posted July 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241885-extract-post-and-get-results-from-a-page-with-authenticationcookies/#findComment-1242197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.