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
Related
I have a web application that I enter an IP Address, username and password into, I then click submit. The page submits this data and redirects to a done page.
The done page finalises the update.
I have to login to access this page and my issue seems to be when I get redirected to the done page my login credentials are not being passed across.
This is the code I'm using :
$ch = curl_init();
$url = "http://127.0.0.1/test/test.cgi?ip=127.0.0.1&user=USERNAME&password=PASSWORD&submit=Update";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$LOGIN:$PASSWORD");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$result=curl_exec($ch);
var_dump($result);
Can anyone advise if I'm missing something or why this may not work ?
Thanks
This works for me:
<?php
$login = 'login';
$password = 'password';
$url = 'http://your.url';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
curl_close($ch);
echo($result);
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 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);
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'm trying to login into twitter with php + curl, but I think there's something wrong with my request because I get this as response:
Something is technically wrong.
Thanks for noticing—we\'re going to fix it up and have things back to
normal soon.
The php code I'm using is:
<?php
$ch = curl_init($sTarget);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $_CKS);
curl_setopt($ch, CURLOPT_COOKIEFILE, $_CKS);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_REFERER, "https://twitter.com");
?>
$sPost looks like this:
session[username_or_email]=user&session[password]=password&remember_me=1&scribe_log=&redirect_after_login=&authenticity_token=6e706165609354bd7a92a99cf94e09140ea86c6f
The code first fetches the login form fields so that the post variables do have the proper values(auth token). I just tried about everything and yes I know there's an api for this but I'd rather find out how to do it manual for learning's sake.
Thanks in advance.
The CURLOPT_COOKIESESSION is used to indicate a new session. That's not what you want, since you need to send the session cookie in the second post.
I got the twitter login to work with this code:
<?php
# First call gets hidden form field authenticity_token
# and session cookie
$ch = curl_init();
$sTarget = "https://twitter.com/";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
curl_setopt($ch, CURLOPT_REFERER, "https://twitter.com/");
$html = curl_exec($ch);
# parse authenticity_token out of html response
preg_match('/<input type="hidden" value="([a-zA-Z0-9]*)" name="authenticity_token"\/>/', $html, $match);
$authenticity_token = $match[1];
$username = "your#email.com";
$password = "password";
# set post data
$sPost = "session[username_or_email]=$username&session[password]=$password&return_to_ssl=true&scribe_log=&redirect_after_login=%2F&authenticity_token=$authenticity_token";
# second call is a post and performs login
$sTarget = "https://twitter.com/sessions";
curl_setopt($ch, CURLOPT_URL, $sTarget);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sPost);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
# display server response
curl_exec($ch);
curl_close($ch);
?>
PS: Sorry for not reading your post properly the first time.
I noticed two things:
1) Try to URL encode your POST data
such as:
session%5Busername_or_email%5D=user&session%5Bpassword%5D=password...
instead of:
session[username_or_email]=user&session[password]=password...
2) twitter has a hidden field named authenticity_token in the login form. It is bound to the session. Thus you cannot use a static authenticity_token, you have to read the login form first and use the authenticity_token field from there.
Hope that helps.