How do I auto-login mediawiki using API login or clientlogin? How do I auto-login mediawiki using API login or clientlogin? curl curl

How do I auto-login mediawiki using API login or clientlogin?


To log in, you need to first GET a logintoken:

$query_string = '?action=query&meta=tokens&type=login&format=json';...// sparing curl_exec details$ResultSerialized = json_decode($Result, true);$Token = $ResultSerialized['query']['tokens']['logintoken'];

Then, you POST the logintoken as well as your username and password:

$post_data = "?action=login&lgname=$username&lgpassword=password&logintoken=$Token&format=json";

And you should be logged in! As long as you keep the same cookie session between all requests, you should be able to use logged-in actions.