logo
down
shadow

How to login to an ASP.NET webpage using PHP cURL?


How to login to an ASP.NET webpage using PHP cURL?

By : Matt Frost
Date : October 16 2020, 03:08 PM
wish of those help You have the keys to the post data incorrect.
You are missing some post fields
code :
<?php  
    header('Content-Type: text/plain; charset=utf-8');



    $post = array('txtUserName$txt'=>'b14080',
    'txtPassword$txt'=>'b14080',
    'btnLogin.x'=>"47",
    'btnLogin.y'=>"16",
    'ddlInstitution$ddl'=>"1",
    '__VIEWSTATE'=>"/wEPDwUKMTM4NDc5NjkwOA9kFgQCAQ9kFggCAw8WAh4JaW5uZXJodG1sBTE8dWwgc3R5bGU9J2xpc3Qtc3R5bGUtdHlwZTogbm9uZTsnPjxsaT48L2xpPjwvdWw+ZAIHD2QWCgIBD2QWBAIBDxAPFgIeC18hRGF0YUJvdW5kZ2QQFQEYS01FQSBFbmdpbmVlcmluZyBDb2xsZWdlFQEBMRQrAwFnFgFmZAIDDw8WDh4RQ29udHJvbFRvVmFsaWRhdGUFA2RkbB4MRXJyb3JNZXNzYWdlBRdJbnN0aXR1dGlvbiBpcyBSZXF1aXJlZB4SRW5hYmxlQ2xpZW50U2NyaXB0Zx4PU2V0Rm9jdXNPbkVycm9yZx4MSW5pdGlhbFZhbHVlBQItMR4PVmFsaWRhdGlvbkdyb3VwBQRTYXZlHgdWaXNpYmxlZ2RkAgMPZBYEAgEPEA8WAh8BZ2QQFQgJMjAxNy0yMDE4CTIwMTYtMjAxNwkyMDE1LTIwMTYJMjAxNC0yMDE1CTIwMTMtMjAxNAkyMDEyLTIwMTMJMjAxMS0yMDEyCTIwMTAtMjAxMRUIAjExAjEwATkBOAE0ATMBNQE2FCsDCGdnZ2dnZ2dnFgFmZAIDDw8WDh8CBQNkZGwfAwUQWWVhciBpcyBSZXF1aXJlZB8EZx8FZx8GBQItMR8HBQRTYXZlHwhnZGQCBQ9kFgZmDw9kFgIeBWNsYXNzBQ1SZXF1aXJlZEZpZWxkZAICDw8WDh8CBQN0eHQfAwUVVXNlciBOY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.108.164';
    $request[] = 'Connection: keep-alive';
    $request[] = 'Pragma: no-cache';
    $request[] = 'Cache-Control: no-cache';
    $request[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
    $request[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36';
    $request[] = 'DNT: 1';
    $request[] = 'Referer: http://117.232.108.164/OnlineTCS/Login.aspx';
    $request[] = 'Accept-Encoding: gzip, deflate';
    $request[] = 'Accept-Language: en-US,en;q=0.8';


    $url = 'http://117.232.108.164/OnlineTCS/Login.aspx';
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
    curl_setopt($ch, CURLOPT_ENCODING,"");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT,10);
    curl_setopt($ch, CURLOPT_FAILONERROR,true);
    curl_setopt($ch, CURLOPT_ENCODING,"");

    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_HEADER, true);


   $data = curl_exec($ch);

    if (curl_errno($ch)){
        $data .= 'Retreive Base Page Error: ' . curl_error($ch);
    }
    else {
      $info = rawurldecode(var_export(curl_getinfo($ch),true));



      $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
      $responseHeader= substr($data,0,$skip);

    // The folowing line is for debug
//    echo "$info\n$responseHeader\n$data\n\n";



       // Get the cookies:
      $e = 0;
      while(true){
        $s = strpos($responseHeader,'Set-Cookie: ',$e);
        if (!$s){break;}
        $s += 12;
        $e = strpos($responseHeader,';',$s);
        $cookie = substr($responseHeader,$s,$e-$s) ;
        $s = strpos($cookie,'=');
        $key = substr($cookie,0,$s);
        $value = substr($cookie,$s);
        $cookies[$key] = $value;
      }

    // Create cookie for subsequent Requests:

     $cookie = '';
     $show = '';
     $head = '';
     $delim = '';
     foreach ($cookies as $k => $v){
       $cookie .= "$delim$k$v";
       $delim = '; ';
     }
}


    $request = array();
    $request[] = 'Host: 117.232.108.164';
    $request[] = 'Connection: keep-alive';
    $request[] = 'Pragma: no-cache';
    $request[] = 'Cache-Control: no-cache';
    $request[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
    $request[] = 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36';
    $request[] = 'DNT: 1';
    $request[] = 'Referer: http://117.232.108.164/OnlineTCS/Login.aspx';
    $request[] = 'Accept-Encoding: gzip, deflate';
    $request[] = 'Accept-Language: en-US,en;q=0.8';


    $url = 'http://117.232.108.164/OnlineTCS/StudentLogin/StudentLoginForm.aspx';
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $request);
    curl_setopt($ch, CURLOPT_ENCODING,"");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT,10);
    curl_setopt($ch, CURLOPT_FAILONERROR,true);
    curl_setopt($ch, CURLOPT_ENCODING,"");

    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_COOKIESESSION , true );
    curl_setopt($ch, CURLOPT_COOKIE, $cookie );

   $data = curl_exec($ch);
   $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
   echo substr($data,$skip);  //do not transmit header


/*   Debug Code
    if (curl_errno($ch)){
        $data .= 'Retreive Base Page Error: ' . curl_error($ch);
    }
    else {
      $info = rawurldecode(var_export(curl_getinfo($ch),true));

     // Get the cookies:

      $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
      $responseHeader= substr($data,0,$skip);

      echo "$info\n$responseHeader\n$data\n\n";

      $e = 0;
      while(true){
        $s = strpos($responseHeader,'Set-Cookie: ',$e);
        if (!$s){break;}
        $s += 12;
        $e = strpos($responseHeader,';',$s);
        $cookie = substr($responseHeader,$s,$e-$s) ;
        $s = strpos($cookie,'=');
        $key = substr($cookie,0,$s);
        $value = substr($cookie,$s);
        $cookies[$key] = $value;
      }

*/
}
 ?>


Share : facebook icon twitter icon
cURL for webpage login

cURL for webpage login


By : bibinc
Date : March 29 2020, 07:55 AM
To fix the issue you can do Ended up using Sikuli scripts for web log in.
After using cURL to log into a remote webpage, how can I then access another webpage and return it as a string?

After using cURL to log into a remote webpage, how can I then access another webpage and return it as a string?


By : Mahesh
Date : March 29 2020, 07:55 AM
may help you . It generally depends on how the remote site handles state management.
In most cases, this will be via a cookie, so you'll need to instruct curl to keep track of cookies.
code :
curl_setopt($curl, CURLOPT_COOKIEJAR, '/tmp/cookies');  //where to write cookies received from server
curl_setopt($curl, CURLOPT_COOKIEFILE, '/tmp/cookies'); //where to read cookies to send in requests.
<?php 
$url ="http://login.yahoo.com/config/login?.src=ym&.intl=us&.partner=&.done=http%3A%2F%2Fmail.yahoo.com%2F"; 
$ch = curl_init();      
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, '/temp/cookie.txt'); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, "login=emailid&passwd=password&&submit=Sign In"); 
ob_start();      
curl_exec ($ch); 
ob_end_clean();  
curl_close ($ch); 
unset($ch); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "/temp/cookie.txt"); 
curl_setopt($ch, CURLOPT_URL,"http://us.f515.mail.yahoo.com/ym/login?"); 
$result = curl_exec ($ch); 

curl_close ($ch); 
echo $result; 
login into webpage with php with cURL

login into webpage with php with cURL


By : Renshan Xia
Date : March 29 2020, 07:55 AM
wish of those help The book you're using is old, and Packt Publishing have changed their website. It now includes a CSRF token, and without passing this you will never be able to log in.
I've developed a working solution. It uses pQuery for parsing the HTML. You can install this using Composer, or download the package and include it into your application. If you do this, remove the require __DIR__ . '/vendor/autoload.php'; and replace with the location to the pquery package on your system.
code :
<?php

require __DIR__ . '/vendor/autoload.php';

$email = 'myemail@gmail.com';
$password = 'mypassword';

# Initialize a cURL session.
$ch = curl_init('https://www.packtpub.com/register');

# Set the cURL options.
$options = [
    CURLOPT_COOKIEFILE      => 'cookies.txt',
    CURLOPT_COOKIEJAR       => 'cookies.txt',
    CURLOPT_RETURNTRANSFER  => 1
];

# Set the options
curl_setopt_array($ch, $options);

# Execute
$html = curl_exec($ch);

# Grab the CSRF token from the HTML source
$dom = pQuery::parseStr($html);
$csrfToken = $dom->query('[name="form_build_id"]')->val();

# Now we have the form_build_id (aka the CSRF token) we can
# proceed with making the POST request to login. First,
# lets create an array of post data to send with the POST
# request.
$postData = [
    'email'         => $email,
    'password'      => $password,
    'op'            => 'Login',
    'form_build_id' => $csrfToken,
    'form_id'       => 'packt_user_login_form'
];


# Convert the post data array to URL encoded string
$postDataStr = http_build_query($postData);

# Append some fields to the CURL options array to make a POST request.
$options[CURLOPT_POST] = 1;
$options[CURLOPT_POSTFIELDS] = $postDataStr;
$options[CURLOPT_HEADER] = 1;

curl_setopt_array($ch, $options);

# Execute
$response = curl_exec($ch);

# Extract the headers from the response
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headerSize);

# Close cURL handle
curl_close($ch);

# If login is successful, the headers will contain a location header
# to the url http://www.packtpub.com/index
if(!strpos($headers, 'packtpub.com/index'))
{
    print 'Login Failed';
    exit;
}

print 'Logged In';
curl command for proxy and webpage login

curl command for proxy and webpage login


By : kiarash
Date : March 29 2020, 07:55 AM
To fix the issue you can do The argument https://url.../ti/v1/attackerdb&format=csv is not quoted in the example, and that's a problem because the & has a special meaning in the shell. Put single or double quotes around it, like this:
code :
curl -o test.csv -vk -x https://url:8000 --proxy-user username1:password1 -L 'https://url.../ti/v1/attackerdb&format=csv' -u username2:password2
Curl a webpage, edit text, then re-open webpage programatically

Curl a webpage, edit text, then re-open webpage programatically


By : zeegee
Date : March 29 2020, 07:55 AM
wish of those help You don't need to do this way. You can use Selenium WebDriver along with HtmlUnit or FireFox to do emulate this behavior.
In Selenium, we create a driver that drives the browser (firefox, chrome, htmlunit etc.). We can perform the operations we want and take screenshots too along the way.
Related Posts Related Posts :
  • intellij idea 2016.2 community edition PHP Support?
  • .htaccess redirect www to non-www with SSL
  • Forgot password API is not working in magento 2.x
  • Executing custom php file from Cron, implementing Wordpress mail send
  • Set a minimum amount in Woocommerce cart except for one category
  • I want to reverse my string as dd/mm/yyy to yyyy/mm/dd
  • error while downloading zip archive from server
  • How to Display images horizontally in html
  • php - how to merge key with subkey in one array
  • How to call function other model in one model?
  • I want to store child nodes on xml file in mysql server
  • php - Make links clickable with http check
  • Live Program Accessing Local Files
  • Laravel - General error: 1366 Incorrect integer value
  • mongodb find query with OR and AND
  • Move Array element using PHP/Laravel
  • How to add new value in collection laravel?
  • PHP Error : Fatal error: Constant expression contains invalid operations
  • Get date of next thursday (including today if we are thursday)
  • PHP Regexp with dash and ampersand doesn't work
  • In MySQL how do I edit multiple records with the same value at the same time?
  • My HTML form only returns 1 value into the PHP mail
  • Create an adjacency structure from a list of sequence
  • PHP Arrays - Merge two arrays where a value is added together
  • Laravel 5.2 persistent session id through login, ok to use _token?
  • syntax error, unexpected 'if' (T_IF),how to resolve
  • nginx 403 forbidden error + mac + laravel
  • Find out whether string has date in it
  • Get values of radio selected values of entire row to next file
  • php preg_replace function wrong result
  • Checkbox not selected based on database value
  • Remove internal array in php
  • How to automatically refresh a page and redirects to login page when session has expired (PHP)
  • Trying to Link a populated drop down list PHP
  • Associate Array Sorting
  • Show Tags with Link from Word String
  • Symfony 3 Dynamic Generation for Submitted Forms not working
  • I want to change the value of a string
  • How to remove category name from url in opencart 2.x?
  • Undefined property: PDOStatement::,$id_login,$nama_depan
  • Getting base path in URL
  • React / Laravel (php) SPA on same (Apache) server
  • In PHP, how can we define a field as a certian class's instance like JAVA?
  • Don't work correctly when clicking on stars
  • php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not knownfailed?
  • Change php to can select the html in css
  • PHP import CSV with umlauts
  • Populate Select based on another Select
  • How to save value after each click with ajax
  • PHP sort array by date and character
  • Duplicate entry for key 'PRIMARY' in mysql code
  • unlink() doesn't work with absolute path
  • DOMXPath - Get Node
  • jQuery - storing variables from PHP foreach loop
  • In Woocommerce, how to use a legacy API instead of the latest version?
  • Mapping home controller as the default controller in AltoRouter
  • Correspondency model - table on CodeIgniter 2
  • Laravel do not validate if field is not required
  • Bootstrap 4.0.0-beta modal won't work. Popper.js is breaking
  • SOAP PHP : how to translate request file to PHP function call
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com