Dokuwiki - Retrieve password protected pages using curl

By xngo on October 7, 2019

Log in and save cookie

Change USERNAME, PASSWORD and the url according to your setup.

curl --cookie cookies.txt --cookie-jar cookies.txt \
        --data "u=USERNAME&p=PASSWORD" \
            "http://localhost/doku.php?id=start&do=login&sectok="

The content of the cookie.txt file will look like the followings.

$cat cookie.txt 
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
 
#HttpOnly_localhost   FALSE   /   FALSE   0   DWbf...XXb8...f6826 eA%3D...7C...%3D
#HttpOnly_localhost   FALSE   /   FALSE   0   DokuWiki    lm47t7ric...bokac0l

Retrieve password protected page

Now, reuse the cookie.txt to indicate to DokuWiki that you are already logged in. From here, you can fetch any pages that require login.

curl --cookie cookies.txt \
        "http://localhost/doku.php?id=private:my-private-page" \
            > my-private-page.html

The fetched page will be stored in my-private-page.html.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.