Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/292885-curl-login-into-website-not-working/
Share on other sites


<?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 by QuickOldCar
<?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

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");

 

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 by brvnbld

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.

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 by brvnbld

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');
}
?>

 

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?

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');
}
?>
  • Like 1

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. ::)

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.