Authenticate on Wordpress with wget Authenticate on Wordpress with wget wordpress wordpress

Authenticate on Wordpress with wget


Try this. This worked for me for one of the Drupal projects I worked on sometime ago. Its answered by asciikewl on the Drupal thread https://drupal.org/node/118759


I've managed to get it working this way, using wget's own cookie handling:I'm also referencing the /user page, not a login block (not enabled on my site)

#!/bin/shsite=http://your site url with a slash on the end/name=ScriptUserpass=somethingsecurecookies=/tmp/cron-cookies.txtwget -O /dev/null --save-cookies /tmp/ba-cookies.txt --keep-session-cookies --load-cookies $cookies "${site}user"wget --keep-session-cookies --save-cookies $cookies --load-cookies $cookies -O /dev/null \    --post-data="name=$name&pass=$pass&op=Log%20in&form_id=user_login" \    "${site}user?destination=login_redirect"wget --keep-session-cookies --save-cookies $cookies --load-cookies $cookies "${site}login_redirect"

Maybe with the wget cookie handling you can recurse the site.


For WordPress, you're only missing a tiny bit, which is the testcookie=1. Also you probably need a User-Agent otherwise you may receive a "403 Forbidden" response.

So all together the script should be:

#!/usr/bin/env bashsite="http://server.com"login_address="$site/wp-login.php"log="username"pwd="password"cookies="/tmp/cookies.txt"agent="Mozilla/5.0"# authenticate and save cookieswget \    --user-agent="$agent" \    --save-cookies $cookies \    --keep-session-cookies \    --delete-after \    --post-data="log=$log&pwd=$pwd&testcookie=1" \    "$login_address"# access home page with authenticated cookieswget \    --user-agent="$agent" \    --load-cookies $cookies \    "$site"

Pro tip:using Chrome Developers tools, in the "Network" tab, you can "Copy as cURL", which is not too far from wget format.

Copy as cURL