brvnbld Posted December 4, 2014 Share Posted December 4, 2014 I am trying to create a remote login to one website using mine. The users will need to enter their username and password on my site, and if they are registered to my website, their login credentials will be sent to another website and a page will be retrieved. I am stuck at sending the users' data to the original site. The original site's viewsource is this.. <form method=post> <input type="hidden" name="action" value="logon"> <table border=0> <tr> <td>Username:</td> <td><input name="username" type="text" size=30></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" size=30></td> </tr> <td></td> <td align="left"><input type=submit value="Sign In"></td> </tr> <tr> <td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <a href="?action=newuser"><font size=-1 color="#0000EE">Sign UP Now !</font></a></td> </tr> </table> I have tried this code, but not works. <?php $username="username"; $password="password"; $url="http://www.example.com/index.php"; $postdata = "username=".$username."&password=".$password; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); header('Location: track.html'); //echo $result; curl_close($ch); ?> Any help would be appreciated, Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/ Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 (edited) <?php $username="username"; $password="password"; $url="http://www.example.com/index.php"; $postdata = array("username"=>$username, "password"=>$password); $fields = http_build_query($postdata); //builds the query $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); $result = curl_exec ($ch); header('Location: track.html'); //echo $result; curl_close($ch); ?> Edited December 4, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498452 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 <?php $username="username"; $password="password"; $url="http://www.example.com/index.php"; $postdata = array("username"=>$username, "password"=>$password); $fields = http_build_query($postdata); //builds the query $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); $result = curl_exec ($ch); header('Location: track.html'); //echo $result; curl_close($ch); ?> no dude, this doesn't work either Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498453 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 i have tried all options to the curl url, like index.php?action=login, logon, etc... Even if i change the curl url to something meaningless, it still displays the same result. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498454 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 I don't see the rest of your form, but how about adding the submit or whatever you may be checking for in your script. $postdata = array("username"=>$username, "password"=>$password, 'submit' => "submit"); Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498455 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 btw, should place the header at the end so curl can close Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498456 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 (edited) I don't see the rest of your form, but how about adding the submit or whatever you may be checking for in your script. $postdata = array("username"=>$username, "password"=>$password, 'submit' => "submit"); This is the whole form, and about the html code, the rest are just head and html tags anyway. still the same error. Edited December 4, 2014 by brvnbld Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498458 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 btw, should place the header at the end so curl can close yeah buddy, corrected that, but still i get the same result. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498459 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 Show the full form and the php code that checks it Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498460 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 ok., html code. <html> <head> <title></title> <link rel="stylesheet" href="styles/main.css" type="text/css" media="print, projection, screen"> </head> <body> <center> <br><br><br><br><br><br><br><br> <div style="border:1px solid #000000;background:#EEEEEE;padding-top:15px;padding-bottom:5px;width:350px;"> <font size=+2>Sign In Form</font><br> <form method=post> <input type="hidden" name="action" value="logon"> <table border=0> <tr> <td>Username:</td> <td><input name="username" type="text" size=30></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" size=30></td> </tr> <td></td> <td align="left"><input type=submit value="Sign In"></td> </tr> <tr> <td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <a href="?action=newuser"><font size=-1 color="#0000EE">Sign UP Now !</font></a></td> </tr> </table> </form> </div> <br> </center> </body> </html> the php code is same, i posted the entire php page. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498461 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 When you send your post form, where does it get the $_POST values in a php script? That's the part not shown. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498462 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 the html code i pasted is from another site, i am trying to login in to another site using a php page. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498463 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 (edited) i think i was not clear. I have a website, users will login to my site, and in return their details will be sent to the other site, and they will get a iframed version of the other site. i am trying to achieve this by creating a login form on my website, then logging in to other site using the data provided by the user by curl, then display the original site, in iframes. Edited December 4, 2014 by brvnbld Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498464 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 Correct, and you are not getting the $_POST values anywhere <?php if(isset($_POST['username']) && trim($_POST['username']) !=''){ $username = trim($_POST['username']); } if(isset($_POST['password']) && trim($_POST['password']) !=''){ $password = trim($_POST['password']); } if(isset($_POST['action']) && trim($_POST['action']) !=''){ $action = trim($_POST['action']); } if(isset($username) && isset($password) && isset($action)){ $url="http://www.example.com/index.php"; $postdata = array("username"=>$username, "password"=>$password, "action" => $action); $fields = http_build_query($postdata); //builds the query $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); $result = curl_exec ($ch); //echo $result; curl_close($ch); header('Location: track.html'); } else { die('Parameters missing'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498465 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 Correct, and you are not getting the $_POST values anywhere <?php if(isset($_POST['username']) && trim($_POST['username']) !=''){ $username = trim($_POST['username']); } if(isset($_POST['password']) && trim($_POST['password']) !=''){ $password = trim($_POST['password']); } if(isset($_POST['action']) && trim($_POST['action']) !=''){ $action = trim($_POST['action']); } if(isset($username) && isset($password) && isset($action)){ $url="http://www.example.com/index.php"; $postdata = array("username"=>$username, "password"=>$password, "action" => $action); $fields = http_build_query($postdata); //builds the query $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); $result = curl_exec ($ch); //echo $result; curl_close($ch); header('Location: track.html'); } else { die('Parameters missing'); } ?> where do i put the username and password? Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498466 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 Point the form to other site where the curl script is With no action posts to same page. <form action="http://www.example.com/index.php" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498467 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 You put the username and password in the form, the form sends to your curl script Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498468 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 The curl script is in my site, the login form is another website, it belongs to someone else, i do not understand how i point the form to the curl site.? Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498469 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 how do i edit someone else's form?, the html code i posted , i took it by going to that site, and selecting view source. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498470 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 make your own login form your site which points to the curl script your site the curl url location would be theirs Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498471 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 Note these lines to edit <form action="curl.php" method="post"> $url="http://other-site.com/login.php"; I hope this helps login.php <html> <head> <title></title> <link rel="stylesheet" href="styles/main.css" type="text/css" media="print, projection, screen"> </head> <body> <center> <br><br><br><br><br><br><br><br> <div style="border:1px solid #000000;background:#EEEEEE;padding-top:15px;padding-bottom:5px;width:350px;"> <font size=+2>Sign In Form</font><br> <form action="curl.php" method="post"> <input type="hidden" name="action" value="logon"> <table border=0> <tr> <td>Username:</td> <td><input name="username" type="text" size=30></td> </tr> <tr> <td>Password:</td> <td><input name="password" type="password" size=30></td> </tr> <td></td> <td align="left"><input type=submit value="Sign In"></td> </tr> <tr> <td align="center" colspan=2><font size=-1>Don't have an Account ?</font> <a href="?action=newuser"><font size=-1 color="#0000EE">Sign UP Now !</font></a></td> </tr> </table> </form> </div> <br> </center> </body> </html> curl.php <?php if(isset($_POST['username']) && trim($_POST['username']) !=''){ $username = trim($_POST['username']); } if(isset($_POST['password']) && trim($_POST['password']) !=''){ $password = trim($_POST['password']); } if(isset($_POST['action']) && trim($_POST['action']) !=''){ $action = trim($_POST['action']); } if(isset($username) && isset($password) && isset($action)){ $url="http://other-site.com/login.php"; $postdata = array("username"=>$username, "password"=>$password, "action" => $action); $fields = http_build_query($postdata); //builds the query $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS,$fields); $result = curl_exec ($ch); //echo $result; curl_close($ch); header('Location: track.html'); } else { die('Parameters missing'); } ?> 1 Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498473 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 A lot of people are untrusting to log into a site using another. Am trying to understand why you would iframe another site versus them just visiting the original site. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498474 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 no, dude, that doesn't work either, it again shows me the track.html i called at the end, but just not logged in. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498475 Share on other sites More sharing options...
brvnbld Posted December 4, 2014 Author Share Posted December 4, 2014 A lot of people are untrusting to log into a site using another. Am trying to understand why you would iframe another site versus them just visiting the original site. The fact is, i have a website, that provides work, and i have employers who can work, but if they see the original site, they will stop working for me, that is why. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498476 Share on other sites More sharing options...
QuickOldCar Posted December 4, 2014 Share Posted December 4, 2014 Does this other site require a cookie or anything? You see the other site and what happens when logs in, hard to help beyond what I tried. Quote Link to comment https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/#findComment-1498477 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.