I've got a cronjob that runs currently that when a certain threshold is reached it tries to open a connection to Instagram and pull all the recently tagged photographs that match that tag.
The problem is when I try to initiate the remote login to "authorize" my application from the commandline using curl, Instagram consistently responds with a webpage stating
This page could not be loaded. If you have cookies disabled in your browser, or you are browsing in Private Mode, please try enabling cookies or turning off Private Mode, and then retrying your action.
This is my curl script.
$username = "<myusername>";
$password = "<mypassword>";
$useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31"; // Yes cause that's the way I roll
$cookie="InstagramCookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/'.$cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/'.$cookie);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
// try to find the actual login form
if (!preg_match('/<form method="POST" id="login-form" class="adjacent".*?<\/form>/is', $page, $form)) {
throw Instagram_Manager('Failed to find log in form!');
}
$form = $form[0];
// find the action of the login form
if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
throw Instagram_Manager('Failed to find login form url');
}
$URL2 = $action[1]; // this is our new post url
// find all hidden fields which we need to send with our login, this includes security tokens
$count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
$postFields = array();
// turn the hidden fields into an array
for ($i = 0; $i < $count; ++$i) {
$postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
}
// add our login values
$postFields['username'] = $username;
$postFields['password'] = $password;
$post = '';
// convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
foreach($postFields as $key => $value) {
$post .= $key . '=' . urlencode($value) . '&';
}
$post = substr($post, 0, -1);
// set additional curl options using our previous options
curl_setopt($ch, CURLOPT_URL, "https://instagram.com/".$url2);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$page = curl_exec($ch);
file_put_contents("/tmp/page.txt", $page);
Any thoughts that you have would be helpful at this point.
Tried your code and works fine after fixing some basic errors.
First of all check that the folder '/tmp' exists and the files inside it are writable and readable.
change
$URL2 = $action[1];
for
$url2 = $action[1];
(variable to lowercase)
And
"https://instagram.com/".$url2
for
$url.$url2
hope it helps
Related
I am working on web scraping after login to Amazon seller central account but while executing my code, it always return me an error
"There was a problem
Enter your email or mobile phone number"
I have checked the cookie file and cookies are saving in it. Set headers as per requirement. Can anyone please let me know where i am lacking.
I have seen many posts which suggest to go with the PhantomJS + CasperJS, but i am not having much time to learn these 2 js. So please help me in resolving this problem.
$email = $username;
// initial login page which redirects to correct sign in page, sets some cookies
$URL = "https://sellercentral.amazon.com/gp/homepage.html?";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/var/www/html/amazoncookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/var/www/html/amazoncookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 10);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://stdout', 'w'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
// try to find the actual login form
if (!preg_match('/<form .*?<\/form>/is', $page, $form)) {
die('Failed to find log in form!');
}
$form = $form[0];
// find the action of the login form
if (!preg_match('/action=(?:\'|")?([^\s\'">]+)/i', $form, $action)) {
die('Failed to find login form url');
}
$URL2 = $action[1]; // this is our new post url
// find all hidden fields which we need to send with our login, this includes security tokens
$count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
$postFields = array();
// turn the hidden fields into an array
for ($i = 0; $i < $count; ++$i) {
$postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
}
// add our login values
$postFields['username'] = $email;
$postFields['password'] = $password;
$post = '';
// convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
foreach($postFields as $key => $value) {
$post .= $key . '=' . urlencode($value) . '&';
}
$post = substr($post, 0, -1);
// set additional curl options using our previous options
curl_setopt($ch, CURLOPT_URL, $URL2);
curl_setopt($ch, CURLOPT_REFERER, $URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$page = curl_exec($ch); // make request
print_r($page);
return $ch;
Reference: "https://github.com/mindevolution/amazonSellerCentralLogin"
Need to scrap product reviews and buyer email ids for the seller feedback after login.
I've searched this website and google but just can't seem to figure out how to get this to work. I'm trying to login to popads.net using a PHP script so I can compile my earnings for my websites onto one page. But this website is giving me trouble. Can anyone see what I'm doing wrong?
<?php
//username and password of account
$username = 'myusername';
$password = 'mypassword';
//set the directory for the cookie using defined document root var
$path = DOC_ROOT."/ctemp";
//login form action url
$url="https://www.popads.net/users/login";
$postinfo = "data[User][username]=".$username."&data[User][password]=".$password;
$cookie_file_path = $path."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
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_exec($ch);
//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, "https://www.popads.net/users/dashboard");
//do stuff with the info with DomDocument() etc
$html = curl_exec($ch);
echo $html;
curl_close($ch);
As this site is using CSRF protection, in order to login you need to first get the CSRF token from the original form and pass this with the login data to the login endpoint. The CSRF token has the field name data[_Token][key] on the homepage. The site may also set a cookie when it sets this so you will need to pass that cookie data back if you get it from cURL.
This said: my recommendation is to see if they have an official API, and before coding a scraper yourself, make sure you're not breeching any terms and conditions which could get you blacklisted.
EDIT 03/26/2017
At some point, PopAds switched to using client side Javascript to generate a check value using two server side variables retrieved from an AJAX request. It looks easy enough to replicate in PHP but since the JS can be easily changed, let's not play cat and mouse and just use an engine to handle the JS for us.
Here is some PHP code to run a CasperJS script to log in and get what we need. First, you'll need to install phpcasperjs/phpcasperjs using Composer. You'll also need nodejs installed, and install the following modules to the directory where you plan to run this script: npm install phantomjs ; npm install casperjs
<?php
require_once 'vendor/autoload.php';
use Browser\Casper;
define('POPADS_EMAIL', 'you#yoursite.com');
define('POPADS_PASS', 'your password');
$casper = new Casper(__DIR__ . '/node_modules/casperjs/bin/');
//$casper->setOptions(['engine' => 'slimerjs']);
//$casper->setDebug(true);
// change the UA!
$casper->setUserAgent('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0');
// navigate to google web page
$casper->start('https://www.popads.net/');
// wait for text if needed for 3 seconds
$casper->waitForText('Reset password', 5000);
//data[User][username]
//data[User][password]
$casper->fillFormSelectors(
'form.didEnabled',
array(
'input#UserUsername' => POPADS_EMAIL,
'input#UserPassword' => POPADS_PASS,
),
true
);
$casper->waitForText('</body>', 5000);
$casper->capturePage(__DIR__ . '/login.jpg');
// run the casper script
$casper->run();
// need to debug? just check the casper output
//$output = $casper->getOutput();
$output = $casper->getHTML();
if (strpos($output, 'PopAds - Dashboard') !== false) {
echo "Logged in!";
} else {
echo "Login failed.";
var_dump($output);
}
Here is a working example. I added some notes to the code. This no longer works, left for reference.
The basic process is:
Request the login form page
Extract "sid" token value from login form
Extract form inputs
Populate form inputs with your login info
Send login post request
Extract balance from the resulting page after being logged in
And the code:
<?php
error_reporting(E_ALL);ini_set('display_errors', 1);
// credentials
$USERNAME = 'username';
$PASSWORD = 'password';
// login url
$LOGINURL = 'https://www.popads.net/users/login';
// initialize curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, ''); // empty file means curl will keep cookies for the lifetime of the handle
// use cookiejar if you'd like to save the cookies for more than the request
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
// set URL and request (establishes cookies, gets login sid)
curl_setopt($ch, CURLOPT_URL, $LOGINURL);
$data = curl_exec($ch);
// look for "sid" value on form action (required)
preg_match('#/users/login\?sid=([\w\d]+)#', $data, $match);
$sid = $match[1];
// extract form fields from form
$formFields = getFormFields($data);
// set username and password
$formFields['data[User][username]'] = $USERNAME;
$formFields['data[User][password]'] = $PASSWORD;
// build http post string
$post_string = http_build_query($formFields);
// update login url with sid value and post login form
curl_setopt($ch, CURLOPT_URL, $LOGINURL . '?sid=' . $sid);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
// execute login request (should be logged in at this point)
$result = curl_exec($ch);
// get balance from page
preg_match('#<h5>Current Balance:</h5>\s*<div class="overview overview_green">(.*?)</div>#is', $result, $balance);
$balance = trim($balance[1]);
// show balance
echo "Your balance is $balance<br>";
function getFormFields($data)
{
if (preg_match('/(<form.*?id=.?UserLoginForm.*?<\/form>)/is', $data, $matches)) {
$inputs = getInputs($matches[1]);
return $inputs;
} else {
die('didnt find login form');
}
}
function getInputs($form)
{
$inputs = array();
$elements = preg_match_all('/(<input[^>]+>)/is', $form, $matches);
if ($elements > 0) {
for($i = 0; $i < $elements; $i++) {
$el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]);
if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) {
$name = $name[1];
$value = '';
if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) {
$value = $value[1];
}
$inputs[$name] = $value;
}
}
}
return $inputs;
}
Output:
Your balance is $0.00
Add:
# Send previously received cookies.
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
Setting CURLOPT_COOKIEJAR only saves cookies received.
Delete:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
This duplicates the next line where you set CURLOPT_POST.
Finally, the second page you are downloading (Dashboard) needs to be fetched with regular GET method. Add this before the second curl_exec() call:
curl_setopt($ch, CURLOPT_HTTPGET, true);
Here is the code that I have been using in order to write a script that logs into my university website in order to pull a file from behind the login.
What consistently happens is that it returns the login page (remembering my username in this form) but it does not authenticate. I have a feeling that the password isn't being transferred, but I don't know why. I've tried looking at the post requests that get sent through my browser when I do it manually, and everything looks fine. Fields should be username and password respectively...
<?php
$username = 'someuser';
$password = 'somepass';
$loginUrl = 'https://vault.andrews.edu/vault/goto/login';
$loginFields = array('username'=>$username, 'password'=>$password); //login form field names and values
$remotePageUrl = 'google.com'; // Will be changed to a remote page
$login = getUrl($loginUrl, 'post', $loginFields); //login to the site
$remotePage = getUrl($remotePageUrl); //get the remote page
function getUrl($url, $method='', $vars='') {
$ch = curl_init();
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies.txt');
$buffer = curl_exec($ch);
print $buffer;
curl_close($ch);
return $buffer;
}
print $login;
?>
Can anybody figure out why it's not going through? I'm sorry that I cannot share real credentials for you all to use.
The login form you're trying to use does not submit to itself. Instead, it submits to https://vault.andrews.edu/vault/app/login/set. Additionally, there is a hidden field in the form which may be required, service with the value http://www.andrews.edu/.
Making those changes:
$loginUrl = 'https://vault.andrews.edu/vault/app/login/set';
$loginFields = array('username'=>$username, 'password'=>$password, 'service' => 'http://www.andrews.edu/');
should fix your script.
you have two ways
first is to add
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
second is supply certificate
like here
SSL Certificate request with cURL
I'm trying to login to Instagram programmatically with PHP and cURL. However, I seem to be missing some detail.
Here is the code:
<?php
$clientID = (my instagram id);
$redirectURI = (my instagram direct uri);
//$url="https://instagram.com/oauth/authorize/?client_id=".$clientID."&redirect_uri=".$redirectURI."&response_type=token";
$url = "https://instagram.com/accounts/login";
$username = (some username);
$password = (some password);
$useragent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31"; // Yes cause that's the way I roll
$cookie="InstagramCookie.txt";
// TODO: find some way to delete the cookie
//unlink($cookie);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/'.$cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/'.$cookie);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$page = curl_exec($ch);
// try to find the actual login form
if (!preg_match('/<form method="POST" id="login-form" class="adjacent".*?<\/form>/is', $page, $form)) {
echo "Failed to find log in form!";
throw Instagram_Manager('Failed to find log in form!');
}
$form = $form[0];
// find the action of the login form
if (!preg_match('/action="([^"]+)"/i', $form, $action)) {
echo "Failed to login from URL";
throw Instagram_Manager('Failed to find login form url');
}
$url2 = $action[1]; // this is our new post url
// find all hidden fields which we need to send with our login, this includes security tokens
$count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields);
$postFields = array();
// turn the hidden fields into an array
for ($i = 0; $i < $count; ++$i) {
$postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i];
}
// add our login values
$postFields['username'] = $username;
$postFields['password'] = $password;
$post = '';
//print_r($postFields);
// convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded
foreach($postFields as $key => $value) {
$post .= $key . '=' . urlencode($value) . '&';
}
$post = substr($post, 0, -1);
//echo $post;
//echo "https://instagram.com".$url2;
//echo $url.$url2;
// set additional curl options using our previous options
curl_setopt($ch, CURLOPT_URL, $url.$url2);
//curl_setopt($ch, CURLOPT_URL, "https://instagram.com".$url2);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$page = curl_exec($ch);
file_put_contents("page.txt", $page);
?>
I have some ideas:
The $url variable is wrong. I want a token for the user, not my app (is there a difference?)
Some kind of cookie trouble. I don't really understand how to manage them well. Should I comment out the $cookie variable or delete the cookie some way?
For a couple of days now I'm trying to login to a specific website using cURL.
The site is in written in ASP.net and I'm using PHP 5.x.
Here is what I've tried so far without success:
$url = "https://intouch.techdata.com/default.aspx?countrycode=&CssStyleSheet=default.css&CultureCode=&local_url=&MPSearchId=&Culture=&cos=";
$cookie_file_path = 'cookies.txt';
$agent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_POSTREDIR, 2);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_POST, 1);
$post_data['__VIEWSTATE'] = "/wEPDwUKLTg1MDYwODIwOA9kFgRmDxYCHgRocmVmBRcvaW1hZ2VzL2RlZmF1bHQuY3NzP3Y9M2QCAQ9kFhgCAw8PFgIeBFRleHQFKldlbGNvbWUgdG8gdGhlIE9ubGluZSBQcm9kdWN0IENhdGFsb2d1ZSBvZmRkAgUPDxYCHwEFIVJlZ2lzdGVyZWQgdXNlcnMgZW
50ZXIgPGJyPiBoZXJlOmRkAgsPFgIeB1Zpc2libGVoFgICAQ8PFgIfAQUJUGFzc3dvcmQ6ZGQCDQ8PZBYCHgxhdXRvY29tcGxldGUFA29mZmQCDw8PFgIfAQUPQWNjb3VudCBOdW1iZXI6ZGQCEQ8PFgIfAQUJVXNlcm5hbWU6ZGQCEw8PFgIfAQUJUGFzc3dvcmQ6ZGQCFQ8PFgIfAQUFTG9naW4WAh4H
b25jbGljawWaAWphdmFzY3JpcHQ6cmV0dXJuIFZhbGlkYXRvcignVXNlcm5hbWU6JywnUGxlYXNlIGVudGVyIGFuIGFjY291bnQgbnVtYmVyJywnUGxlYXNlIGVudGVyIHlvdXIgdXNlcm5hbWUnLCdBcmUgeW91IHN1cmUgeW91IHdhbnQgdG8gY2hhbmdlIHRoZSBwYXNzd29yZCcsJzAnKTtkAhcPDxY
CHwEFBUxvZ2luFgIfBAWaAWphdmFzY3JpcHQ6cmV0dXJuIFZhbGlkYXRvcignVXNlcm5hbWU6JywnUGxlYXNlIGVudGVyIGFuIGFjY291bnQgbnVtYmVyJywnUGxlYXNlIGVudGVyIHlvdXIgdXNlcm5hbWUnLCdBcmUgeW91IHN1cmUgeW91IHdhbnQgdG8gY2hhbmdlIHRoZSBwYXNzd29yZCcsJzAnKT
tkAhkPDxYCHwEFBVJlc2V0FgIfBAUcamF2YXNjcmlwdDpyZXR1cm4gZm5SZXNldCgpO2QCHQ8PFgIfAQUOUGFzc3dvcmQgbG9zdD8WBB8EBZoBamF2YXNjcmlwdDpyZXR1cm4gVmFsaWRhdG9yKCdVc2VybmFtZTonLCdQbGVhc2UgZW50ZXIgYW4gYWNjb3VudCBudW1iZXInLCdQbGVhc2UgZW50ZXIgeW
91ciB1c2VybmFtZScsJ0FyZSB5b3Ugc3VyZSB5b3Ugd2FudCB0byBjaGFuZ2UgdGhlIHBhc3N3b3JkJywnMScpOx8ABTRqYXZhc2NyaXB0OmdvKCdERUZBVUxUQ2hwLkNTUycsJycsJ2RlZmF1bHQuY3NzJywnJyk7ZAIfDw8WBB8BBRBCZWNvbWUgYSBQYXJ0bmVyHwJoFgIfAAU0amF2YXNjcmlwdDpCZW
NvbWVBUGFydG5lcigncD1CZWNvbWVQYXJ0bmVyJmM9SG9tZScpO2RkxaBIRC+v+vJslZdN4xAvkZL9HCY=";
$post_data['__EVENTVALIDATION='] = "/wEWEALxt7yuBwKs+5bqDwKl1bKzCQK1qbSRCwLFp6CQBwLCi9reAwKgt7D9CgKY5fiZAQLnxpq/AgKT2dzTDQK7hrWFCgKsuviBAQLnw+O9BAKywsaqBgL43fTxBQLonLasDzE6BdS22kepzqbhlPQS//T5e2ty";
$post_data['txtID'] = 'idnumber';
$post_data['txtUserName'] = 'username';
$post_data['txtDupPassword'] = 'password';
$post_data['Session_ID'] = '';
$post_data['sessionid'] = '';
$post_data['errorCode'] = '';
$post_data['hdnSavedSearch'] = '';
$post_data['hdnProdIds'] = '';
$post_data['hdnMPSearchId'] = '';
$post_data['hdnDisplaytype'] = '';
$post_data['hdnMode'] = '';
$post_data['hdnProductid'] = '';
$post_data['hdnQuantity'] = '';
$post_data['hdnBanner'] = '';
$post_data['cos'] = '';
$post_data = http_build_query($post_data);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data);
$out = curl_exec($ch);
echo $out;
The thing is that I get a server runtime error as response. I don't really know how am I supposed to form the url maybe. Any help on this?
Thanks in advance
EDIT:
Here's another post that is about curl: Trying to connect to ASPX site using CURL?
I'm not sure how exactly you might do this with curl, but it is relatively easy to post credentials to a website for logging in. Please see the following posts on the matter:
Programmatically logging into a site
Using c#/ASP.NET to programmatically fake a login to a website
The process works like this:
(1) make a GET request to the web page
(2) grab the __VIEWSTATE from the response you receive
(3) make a post to the url with the desired credentials appended in the following format:
yourtargetwebsiteaddress.com/targetloginpage?__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={VS}&__EVENTVALIDATION={EV}&{UserNameControl}={UN}&{PasswordControl}={PW}
WHERE
{VS} is the the View state from your initial request
{EV} is the event validation from your initial request
{UserNameControl} is the id of the username control, {UN} is the username you'd like to post
{PasswordControl} is the id of the password control on the web page, {PW} is the password you'd like to post