php - Logging in to external website(s) with cURL -
i'm trying log in external website using curl. want user enter username , password on index page, , when user clicks on submit button, loginform post both username , password logincheck.php. there checks if username registered in database. if true, should forward username , password external site , try logging in there. if not, should see echo saying "failed".
<?php error_reporting(-1); ob_start(); $host="xxxxxxx"; $username="xxxxxxx"; $password="xxxxxxx"; $db_name="xxxxxxx"; $tbl_name="xxxxxxx"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $myusername=$_post['loginid']; $mypassword=$_post['password']; $loginurl1 = 'http://externalwebsite.com/'; $myusername = stripslashes($myusername); $myusername = mysql_real_escape_string($myusername); $sql="select * $tbl_name login='$myusername'"; $result=mysql_query($sql); if (false === $result) { echo mysql_error(); exit; } $count=mysql_num_rows($result); $cookiefile = "test/mycookiefile.txt"; if(!file_exists($cookiefile)) { $fh = fopen($cookiefile, "w"); fwrite($fh, ""); fclose($fh); } if($count==1){ session_start(); $_session['myusername'] = $myusername; $curl = curl_init(); curl_setopt($curl, curlopt_url, $loginurl1); curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, 'gebruikersnaam='.$myusername.'&wachtwoord='.$mypassword); curl_setopt($curl, curlopt_failonerror, true); curl_setopt($curl, curlopt_followlocation, true); curl_setopt($curl, curlopt_cookiefile, $cookiefile); curl_setopt($curl, curlopt_cookiejar, $cookiefile); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_ssl_verifyhost, false); curl_setopt($curl, curlopt_ssl_verifypeer, false); curl_exec($curl); $result = curl_exec($curl); header('location: http://externalwebsite.com/'); curl_close(); } else { echo "failed"; } ob_end_flush(); ?>
now, redirects fine external website, won't attempt log in on site, no matter try. doing wrong? missing something?
Comments
Post a Comment