fix3r Posted May 12, 2007 Share Posted May 12, 2007 I want to use php to login to another site and then go to that site using the screen name I was logged into and view a webpage on that site and submit a form and searching for text mostly, i need help logging into that site through a php script.. how would I go about doing this Link to comment https://forums.phpfreaks.com/topic/51014-php-login-to-other-site-using-curl/ Share on other sites More sharing options...
fix3r Posted May 12, 2007 Author Share Posted May 12, 2007 <?php $headers = array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0. Gecko/20061025 Firefox/1.5.0.8"); $url="THE WEBSITE"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "email=email&pass=pass"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_MAXREDIRS, 4); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $store = curl_exec ($ch); curl_close ($ch); print_r($store); ?> Okay, I got the login to work. Now, how would I make it go to an existing page with the login information and then submit a whole new form? That I am a little confused about. Link to comment https://forums.phpfreaks.com/topic/51014-php-login-to-other-site-using-curl/#findComment-251037 Share on other sites More sharing options...
fix3r Posted May 12, 2007 Author Share Posted May 12, 2007 Okay, sorry for spam. It seems that this code still outputs the html of the site. How do I make it not output the site at all? $url="WEBSITE"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies1.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies1.txt'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "ALL MY FIELDS"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_MAXREDIRS, 4); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $store = curl_exec ($ch); curl_close ($ch); //print($store); Link to comment https://forums.phpfreaks.com/topic/51014-php-login-to-other-site-using-curl/#findComment-251066 Share on other sites More sharing options...
chigley Posted May 12, 2007 Share Posted May 12, 2007 <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.externalsite.co.uk/login.php"); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=foo&password=bar"); curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $login = curl_exec ($ch); curl_setopt($ch, CURLOPT_URL, "http://www.externalsite.co.uk/memberspage.php"); $members = curl_exec ($ch); curl_close ($ch); ?> You now have a variable, $members, which contains the HTML output of memberspage.php after logging in with the username foo and password bar. Hope that helps.. and works! Link to comment https://forums.phpfreaks.com/topic/51014-php-login-to-other-site-using-curl/#findComment-251175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.