How do you handle authentication via cookie with CURL?
May 19, 2005 6:57 PM
Subscribe
how do you handle authentication via cookie with CURL?
I’ve been assigned a tedious job at work. I wrote a PHP script to do it for me, but it requires CURL, which I’ve never used before. Basically I have to replace text in a file with text from various sources. I’m uploading a set of files to my webhost (company doesn’t use PHP), running the script and outputting them to a separate file. The problem is one of the sources I’m getting data from is the company website, which is password protected. I have a password and username, but I’m not sure how CURL deals with them. Once they’ve been entered, a cookie is stored to save auth status.
Do I just use http://name:passwd@machine.domain/full/path/to/file and let CURL handle everything? Or do I have to tell it how to handle the cookie? Or am I not getting this at all?
Thanks.
posted by miniape to computers & internet (8 comments total)
curl -d "username=miniape&password=SeCrEt" http://whatever.com/login
and if you want to store the cookie that comes back you do so by specifying a cookie file:
curl -c cookies.txt -d "username=miniape&password=SeCrEt" http://whatever.com/login
and to use those cookie in later requests you do:
curl -b cookies.txt -d "username=miniape&password=SeCrEt" http://whatever.com/login
or do both if you want to both send and receive cookies:
curl -b cookies.txt -c cookies.txt -d "username=miniape&password=SeCrEt" http://whatever.com/login
By the way, I learned all this in the last couple of minutes by Googling for "curl". Just sayin'.
posted by nicwolff at 7:30 PM on May 19, 2005