use curl to save login cookies

I have no real experience working with curl, so I probably need some help.

I have a php script that needs access to a file called redownloadsubmitter.jsp, but when I try it fails because the php script on my server has no authentication done prior to accessing the script.

The login script is located in portalloginsubmitter.jsp

How can I "login" with the PHP script and then afterwards access the downloadsubmitter to download the needed data?

I read some articles about curlopt_cookiejar, but I can't seem to get it how I need to go about it. Help?


This link should help:

In summary. Hit the page where the cookies are generated (EX: before you need them), then use this in the curl request.

curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");

Make sure you execute and close it, to get the cookie jar to store the cookies. They are only stored on the closing of the curl request. On the next response (ex: when you require the cookies).

Add this into it.

curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");

Just a note from experience making automated scripted log ins, most scripts require way more than just cookies. Some will require some of the below mentioned things.

  • generated form data that is generated on each load and must be passed (so scrape the page, pull the data, then insert it on the submission of next page)
  • cookies - (explained above)
  • null referrers / user-agents sometimes are not allowed, so make sure you pass a referrer and a user-agent in the requests.

Need Your Help

When to use bind() when programming with sockets?

c sockets unix network-programming

I am writing a simple sender and receiver program to transit using UDP so it's connectionless, but I am having a problem figuring out whether my receiver program needs to call bind() or the server ...