How to get Laravel's CSRF Token from Another Website?

822 views Asked by At

I want to get a csrf token from another web's form. I've tried to get that token with cUrl. I guess that was success, but I think the real problem is that another web's form couldn't refresh the Token until the form is well filled and submitted while my web form is always refresh that token every time I refresh the page.

So this is my cUrl code:

<?php
function bacaHTML($url)
{
    // inisialisasi CURL
    $data = curl_init();
    // setting CURL
    curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($data, CURLOPT_URL, $url);
    // menjalankan CURL untuk membaca isi file 
    $hasil = curl_exec($data);
    curl_close($data);
    return $hasil;
}

$kodeHTML = bacaHTML('http://bla-bla-bla.id/yeah');
$pecah = explode('<form action="http://bla-bla-bla.id/yeah" name="donasi" id="donasi" method="post">', $kodeHTML);
$pecahLagi = explode('<input type="hidden" name="user_id" id="user_id" value="">', $pecah[1]);

echo $pecahLagi[0];
?>

And i got this

<input type="hidden" name="_token" value="qRIDbrYH4MvFdhIe2sP9Rtp17C6SaDf9quSsbIOH">

But that token is not generated until that web form well filled while in my form was generated as I said before so my form can't pass data to that web form. For your information, that web was builder with Laravel. Can anybody help me? And sorry for my bad English. I'm new to programming

1

There are 1 answers

1
Isaac ghorbani On

hi the right way is disable csrf token on route in

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
       //add route here

    ];
}