PHP cURL with authentication

Associate
Joined
23 Mar 2009
Posts
348
Location
Midlands
Hey all,

I'm trying to scrape the activity feed from the Barclay's Cycle Hire website but have come to a dead end because the page with the login form seems to set a hidden POST variable, so I'll need to retrieve and cache that in cURL, but not sure how :(

The login form is here:
https://web.barclayscyclehire.tfl.gov.uk/

It seems to submit three POST variables:

login[Username]
login[Password]
login[_csrf_token]

The csrf_token one seems completely random each time you load the page... so not sure how to do this in cURL :(

edit:
Basic form code:
Code:
<form action="/" method="post">
       <fieldset>
                        <label for="login_Email">Email address</label>                        <input autocomplete="off" size="40" maxlength="254" type="text" name="login[Email]" id="login_Email" />
                        <label for="login_Password">Password</label>                        <input autocomplete="off" size="20" maxlength="16" type="password" name="login[Password]" id="login_Password" />
                        <!-- SUBMIT BUTTON -->
                        <input type="submit" value="Sign in" class="button-default-1" />
            <!-- TOKEN -->
                        <input type="hidden" name="login[_csrf_token]" value="a213399200aa6fb6d90e3de70835d23d" id="login__csrf_token" />       </fieldset>
	</form>

edit2!: I tried using pret_match to grab the value but I think it gets a different value when cURL connects to the site
 
Last edited:
Have you tried grabbing the token with one CURL request and sending it back (with user + pwd) on another?

I'd have a look at the headers on the first request, especially for anything session based, and would send those back (use the --header/-h parameter) along with the 'login' request.

Also have a go at using Fiddler, it might help you to see what data is being swapped when you go to the page and login.
 
Really sorry to bump an old thread, but sort of gave up based on the above advice, however I've just seen somebody has released an android app which does what I'm trying to do... so there must be a way!!

I've played around with cURL but haven't used it for any advanced stuff before so not sure what to do about the csrf token :(

Any help would be HUGELY appreciated :)
 
Well the [_csrf_token] isn't completely random on each page load, rather it changes depending on if a cookie is stored or not. So have a look at the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE options of CURL and see if that works.
You're still going to have to call CURL twice - once for grabbing the token and setting the cookie, another to send the token/cookie and username/password.
 
Back
Top Bottom