Announcement

Collapse
No announcement yet.

login PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • login PHP

    Hello
    anyone can help me
    I can not login with php

    I have no answer
    where am I wrong?



    code
    **************************************************


    <?php
    define('APP_KEY', 'XXXXXXXXX'); //enter your application key
    define('USERNAME', 'XXXXXX'); //enter your betfair username
    define('PASSWORD', 'XXXX'); //enter your betfair password
    define('SESSION_TOKEN', bot_login());

    echo SESSION_TOKEN;

    function bot_login() {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://identitysso.betfair.com/api/login");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'X-Application: ' . APP_KEY,
    'Accept: application/json'
    ));

    curl_setopt($ch, CURLOPT_SSLCERT, CERT);
    $postData = '?username=' . USERNAME . '&password=' . PASSWORD;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    echo $postData;
    $response = json_decode(curl_exec($ch));
    if (empty($response->sessionToken)) {
    echo 'No sessionToken, Response: ' . json_encode($response);
    exit(-1);
    } else {
    return $response->sessionToken;
    }
    }




    tanks

  • #2
    I'm trying to work out how to do with with VB.Net. I haven't written any PHP for many years.

    What did your $ch and $postData look like in the end?

    I suspect the question mark in your $postData may not be wanted.

    Comment


    • #3
      Login Keepalive Logout

      Browsing the forum I see this thread has over 23000 views but no solution posted! Typically I would use curl for this but lately I've been exploring PHP's native functions so had this code to hand - it probably has a few bits that aren't needed.

      It would seem that PHP is often not configured correctly for HTTPS(SSL), it looks for cert bundles in wrong places. If you can't fix the configuration then you can temporarily tell PHP where to look with the 'capath' context option.

      This script is for secure cert based login, for automated non-interactive usage. You'll need to generate your certificate and key as per instructions in the getting started guide.

      PHP Code:
      <?php
      // Login Keepalive Logout

      // Only tested on linux
      // This is for automated login using a cert and key file that you've 
      // previously generated and registered with your betfair account. 
      // Requires additional error checking to be more robust.
      // Security warning: This script & BF_CERT & BF_KEY should not be web accessible.


      define("BF_USERNAME""");
      define("BF_PASSWORD""");
      define("BF_APP_KEY""");
      define("BF_CERT"__DIR__."/client-2048.crt"); // assumes our cert and key files
      define("BF_KEY"__DIR__."/client-2048.key");  // are in same dir as this script


      echo "Login for user " BF_USERNAME "\n";
      $opts = [
          
      'ssl' => [
      //        'capath' => '/etc/ssl/certs/',
              
      'CN_match' => 'betfair.com',
              
      'verify_peer' => true,
              
      'local_cert' => BF_CERT,
              
      'local_pk' => BF_KEY
          
      ],
          
      'http' => [
              
      'method'  => 'POST',
              
      'header'  => [
                  
      'Content-type: application/x-www-form-urlencoded',
                  
      'X-Application: ' BF_APP_KEY,
                  
      'Accept: application/json'
              
      ],
              
      'content' => http_build_query([
                  
      'username' => BF_USERNAME,
                  
      'password' => BF_PASSWORD
              
      ])
          ]
      ];
      $context  stream_context_create($opts);
      $json file_get_contents('https://identitysso.betfair.com/api/certlogin'false$context);
      $response json_decode($json);
      print_r($response);
      if (
      $response->loginStatus != "SUCCESS") die("login failed - loginStatus: {$response->loginStatus}\n");
      $mysession $response->sessionToken// we now have a session token
      echo "Ok.\n\n";



      echo 
      "Keepalive using session $mysession\n";
      $opts = [
          
      'ssl' => [
      //        'capath' => '/etc/ssl/certs/',
              
      'CN_match' => 'betfair.com',
              
      'verify_peer' => true
          
      ],
          
      'http' => [
              
      'method'  => 'GET',
              
      'header'  => [
                  
      'X-Authentication: ' $mysession,
                  
      'X-Application: ' BF_APP_KEY,
                  
      'Accept: application/json'
              
      ]
          ]
      ];
      $context  stream_context_create($opts);
      $json file_get_contents('https://identitysso.betfair.com/api/keepAlive'false$context);
      $response json_decode($json);
      print_r($response);
      if (
      $response->status != "SUCCESS") die("keepalive failed - error: {$response->error}\n");
      echo 
      "Ok.\n\n";



      echo 
      "Logout using session $mysession\n";
      $opts = [
          
      'ssl' => [
      //        'capath' => '/etc/ssl/certs/',
              
      'CN_match' => 'betfair.com',
              
      'verify_peer' => true
          
      ],
          
      'http' => [
              
      'method'  => 'GET',
              
      'header'  => [
                  
      'X-Authentication: ' $mysession,
                  
      'X-Application: ' BF_APP_KEY,
                  
      'Accept: application/json'
              
      ]
          ]
      ];
      $context  stream_context_create($opts);
      $json file_get_contents('https://identitysso.betfair.com/api/logout'false$context);
      $response json_decode($json);
      print_r($response);
      if (
      $response->status != "SUCCESS") die("logout failed - error: {$response->error}\n");
      echo 
      "Ok.\n\n";

      ?>
      Output:

      Login for user XXXXXXXXX
      stdClass Object
      (
      [sessionToken] => YYYYYYYYYYxE0/uOk7eb5h6YdVfgov6EbjQKSG727s=
      [loginStatus] => SUCCESS
      )
      Ok.

      Keepalive using session YYYYYYYYYYxE0/uOk7eb5h6YdVfgov6EbjQKSG727s=
      stdClass Object
      (
      [token] => YYYYYYYYYYxE0/uOk7eb5h6YdVfgov6EbjQKSG727s=
      [product] => ZZZZZZZZZZigHOie
      [status] => SUCCESS
      [error] =>
      )
      Ok.

      Logout using session YYYYYYYYYYxE0/uOk7eb5h6YdVfgov6EbjQKSG727s=
      stdClass Object
      (
      [token] => YYYYYYYYYYxE0/uOk7eb5h6YdVfgov6EbjQKSG727s=
      [product] => ZZZZZZZZZZigHOie
      [status] => SUCCESS
      [error] =>
      )
      Ok.

      Comment


      • #4
        Thank you for the code.

        I have the .pem certificate, but I don't have the .key or .crt ones.

        Where can i get those?

        my output is:

        stdClass Object ( [loginStatus] => CERT_AUTH_REQUIRED ) login failed - loginStatus: CERT_AUTH_REQUIRED

        Comment


        • #5
          Usually PEM is combined of .crt and .Key. Please open the .PEM file and you can create the .CRT and .KEY because i have done that.

          Comment


          • #6
            I'm trying to figure out how to do it with VB.Net. I haven't written PHP for many years.

            What did your $ch and $postData look like at the end?

            I suspect the question mark in your $postData might be undesirable. I've been doing research on this for a long time, but I haven't found a solution yet.

            Please help.

            Comment


            • #7
              Hi, good afternoon everyone!

              Could someone provide me with some working in PHP?

              my biggest problem is that I only know how to work with PURE PHP, so I need something already working...

              Thanks in advance!!!

              Comment

              Working...
              X