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);
Related
When i login through htaccess loginbox i can navigate all files but when i login through curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERPWD,$_SESSION['numerTelefonu'].":".$_SESSION['smsHaslo']);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
echo $result;
Then every time when i go to other file, browser ask about pass.
How to save login data in session?
recently I've been working on a little project in order to post some information into a login page so I can access my schedule for school easily. Anyways the problem is I'm not able to post the password onto the website or submit the credentials. The only thing that actually works is posting the username. Here is the code:
<?php
$ch = curl_init();
$datafield = '__VIEWSTATE=%2FwEPDwULLTE2OTMyMjE5NzBkZKC3UMzpz2mvo4EH%2FkIAaElJ4cqX&__EVENTVALIDATION=%2FwEdAASUve01SuLnSrJ144bDmbDAY3plgk0YBAefRz3MyBlTcHY2%2BMc6SrnAqio3oCKbxYainihG6d%2FXh3PZm3b5AoMQa2TJXV1d0bJySVXtESf1LAcmqGM%3D&txtUserName=12345678&txtPassword=Password12345&btnLogin=Login';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fhhs');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datafield);
curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fSchedulePrint.aspx');
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
I've looked through many threads but I still don't understand the issue. Any help would be appreciated. Also of course those aren't the real credentials.
Edit:
So I changed the code to this and I removed the duplicate CURLOPT_URL but now not even the Username is being inputted. Nothing is happening, the page just displays with nothing occuring.
<?php
$ch = curl_init();
$username = '12345678';
$password = 'Password12345';
$datafield = array('txtUserName' => $username, 'txtPassword' => $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL, 'https://studentportal.eschooldata.com/Login.aspx?ReturnUrl=%2fhhs');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datafield));
curl_exec($ch);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
?>
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 am trying to fetch a json string from a password protected url.
I think my code should work but when I open my script in the browser I just have a blank page.
Here's my code:
<?php
error_reporting(E_ALL);
$url = 'https://api.domain.com?api=latest&format=json';
$username = 'username';
$password = 'password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//curl_setopt($ch, CURLOPT_REFERER, $url);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$data = json_decode($result, true);
print_r($data);
?>
Any help would be much appreciated.
Try adding this
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);