Jak ominąć zabezpieczenie csrf-token przy formularzach? (php)

0

Potrzebuję usunąc zabezpieczenie csrf-token przy formularzu.

Niestety mimo kilku prób nie udaje się tego obejść, od razu mówie że nie mam dostępu do strony do której potrzebuję wysłać formularz POSTEM.

Url: https://rejestracja.kolporter.com.pl/auth/login

Moj kod: http://pastebin.com/ntDVs7NT

Błąd: 'Whoops, looks like something went wrong.'

0

Dobra rada.... ** Nie kombinuj jak koń pod górę **

2

Dostosuj odpowiednio.

use GuzzleHttp\Client;
use GuzzleHttp\TransferStats;
use Masterminds\HTML5;

function logIn($login, $password, Client $client, HTML5 $dom_parser)
{
    $response = $client->request('GET', 'https://mojastrona.com/login');
    $dom = $dom_parser->loadHTML($response->getBody());
    $inputs = $dom->getElementsByTagName('input');
    $csrf_token = '';
    foreach ($inputs as $input) {
        /** @var DOMElement $input */
        if ($input->getAttribute('name') === '_csrf_token') {
            $csrf_token = $input->getAttribute('value');
        }
    }
    if (empty($csrf_token)) {
        throw new Exception('Unable to authenticate');
    }
    // http://stackoverflow.com/questions/30682307/how-to-read-the-response-effective-url-in-guzzle-6-0
    $current_url = null;
    $client->request('POST', 'https://mojastrona.com/login', [
        'form_params' => [
            '_email' => $login,
            '_password' => $password,
            '_csrf_token' => $csrf_token
        ],
        'on_stats' => function (TransferStats $stats) use (&$current_url) {
            $current_url = $stats->getEffectiveUri();
        }
    ]);
    // after successful login we should be redirected to https://mojastrona.com/
    if ((string)$current_url !== "https://mojastrona.com/") {
        throw new Exception('Authorization failed.');
    }
    return true;
}

// Use a shared client cookie jar for all requests.
$client = new Client([
    'cookies' => true
]);
$dom_parser = new HTML5();
logIn('john_doe', 'jane123', $client, $dom_parser);

1 użytkowników online, w tym zalogowanych: 0, gości: 1