Login with PHP curl and CSRF token

后端 未结 3 882
忘了有多久
忘了有多久 2021-01-07 02:05

I want login from a PHP script to another website but I always get this reply:

403 Error: CSRF token mismatch

I extract the CSRF token from

3条回答
  •  攒了一身酷
    2021-01-07 02:16

    You are making your first request with file_get_contents and your second request with cURL.

    You've set up a cookie jar for the second request, but not for the first request. Consequently, each of those two requests is starting a new session.

    CSRF tokens are stored in the session by the server you are making the request to, so the token you get the first request won't match the token in the session for the second request.

    You need to:

    • Use cURL consistantly
    • Use the same cookie jar for both requests

提交回复
热议问题