i'm trying to login and submit another contact form using PHP cURL.
Below is my script,
<?php
echo login_curl();
function login_curl() {
//First Form post data's
$postfields = array();
$postfields["formUsername"] = urlencode("xxx");
$postfields["formPassword"] = urlencode("xxx123");
//Define option variables
$action ="http://www.websss.com/websss/authenticate.php";
$cookie = "cookie.txt";
$agent = "Mozilla/26.0";
$referer = "http://www.websss.com/websss/login.php";
//Second form post data's
$secpostfields = array();
$secpostfields["form_url"] = urlencode("http://web.com");
$secpostfields["form_desc"] = urlencode("Jquery web Link");
//Define option variables
$secondaction ="http://www.websss.com/websss/insert_link.php";
$secondreferer = "http://www.websss.com/websss/login.php";
// Submit Login Form
$ch = curl_init($action);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Capture output and close session
$result = curl_exec($ch);
curl_close($ch);
//submit second form after login
$secondch = curl_init($secondaction);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $secpostfields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $secondreferer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Capture output and close session
$resultsecond = curl_exec($secondch);
curl_close($secondch);
return $resultsecond;
}
?>
I can note that, above script logging in properly but it's not submitting second form.
Did anyone know where i'm going wrong ?
Try don't close the session between first and second post.
And just modify url and post options you need to change
...
//Capture output and don't close session
$result = curl_exec($ch);
//curl_close($ch);
//submit second form after login
curl_setopt($ch, CURLOPT_URL, $secondaction);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $secpostfields);
curl_setopt($ch, CURLOPT_REFERER, $secondreferer);
$resultsecond = curl_exec($ch);
Related
I am trying to scrap event lists data from festivalnet. Which can only be retrieved after login. I try it in PHP using Curl. But Not able to login in festivalnet page, I am Posting parameters with curl.
//username and password of account
$login_username = 'abcd';
$password = 'xxxx';
//login form action url
$form_url="https://festivalnet.com/cgi-bin/festbiz2/db.cgi";
$postinfo = "userid=".$login_username."&pw=".$password.'&db=festbiz&login=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $form_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
It redirect to https://festivalnet.com/cgi-bin/festbiz2/db.cgi?db=festbiz&login=3&return_to=%2Ffno%2Findex.php%3Fmode%3Dcp
Please help.
Try CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR.
The usage is shown here
I'm trying to get json data from this page https://www.rbauction.com/rba-api/search/results/advanced?rbasq=YXJ8Tj00Mjk0MjM4MzMyKzQyOTQ5NjU3OTg=&offset=2&count=1&ccb=USD
when i visit that page from browser it will ask me to login, when logged in it will display the json right away upon login. what need to do is get that json data with php using curl.
$username = 'myemail';
$password = 'mypass';
$loginurl = 'https://www.rbauction.com/myaccount';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '_58_login='.$username.'&_58_password='.$password);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $store = curl_exec($ch);
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_setopt($ch, CURLOPT_URL, 'https://www.rbauction.com/rba-api/search/results/advanced?rbasq=YXJ8Tj00Mjk0MjM4MzMyKzQyOTQ5NjU3OTg%3D&offset=2&count=1&ccb=USD');
$store = curl_exec($ch);
var_dump($store);
when i do var_dump its just showing empty string
I'm trying to login to Square (squareup.com/login) to retrieve some information about my business and send me an email. However, my ability to make cURL work properly has not made any progress for several days so I'm asking for help.
Here's my code:
$email = 'myemail';
$password = 'mypassword';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$tokenurl = 'https://squareup.com/login/';
curl_setopt($ch, CURLOPT_URL, $tokenurl);
$content = curl_exec($ch);
$get_auth_token = strstr($content, 'input name="authenticity_token" type="hidden" value="');
$auth_token = substr($get_auth_token,53,44);
$loginUrl = 'https://www.squareup.com/login/';
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email='.$email.'&password='.$password.'&authenticity_token='.$auth_token);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$store = curl_exec($ch);
$fileurl = 'https://squareup.com/dashboard';
curl_setopt($ch, CURLOPT_URL, $fileurl);
$content = curl_exec($ch);
file_put_contents('data.txt', $content);
The result in my data.txt file is either the login page being displayed again (as in, it didn't login correctly).
Any tips appreciated!
I have written a script in PHP cURL to fill form.
but strangely the form is only getting filled and there is no submission of form
here is the code
please help
$cookies = 'C:\wamp\www\costie\cookies.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url1); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 0); // times out after Ns
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_POSTFIELDS, "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=$value1&__PREVIOUSPAGE=$value2&__EVENTVALIDATION=$value3&$name1=2008&$name2=02-33-255-009&$name3=&$name4=&$name5=");//ADD post fields
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies);
$result = curl_exec($ch); // run the whole process
curl_close($ch);
echo $result;
I try to login in a site which has a combined login.
The redirect to this site works fine and the redirect back as well ... but only if I stop the PHP programm with die(). Unfortunately it is not stored in $return, which I would need to proceed.
Any ideas, what I am doing wrong? Much appreciated!
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, TRUE);
curl_setopt($ch, CURLOPT_POSTREDIR, TRUE);
curl_setopt($ch, CURLOPT_URL, URI_LOGIN);
$content = curl_exec($ch);
// PREPARING THE LOGIN
$referer = URI_LOGIN . '?ReturnUrl=' . urlencode('/returnUrl/');
curl_setopt($ch, CURLOPT_URL, $referer);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE);
$post = ...;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post) );
curl_setopt($ch, CURLOPT_USERAGENT, '...');
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
$content = curl_exec($ch);
// LOGIN
curl_setopt($ch, CURLOPT_URL, COMBINED_LOGIN);
$post = ...;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post) );
$return = curl_exec($ch);
// ...
?>
There was a problem with javascript. It stucked on an 'in-between'-page and I had to make another curl request to get to the right page.
Now it is working fine!