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

Define the size of a global array from the command line

c pthreads global-variables command-line-arguments semaphore

I am doing an assignment where I need to use pthreads or semaphores to synchronize some processes which access some shared resource. Since all of our examples in class use a global variable as the

What sed script can replace a range of hex characters with another

search replace sed binary hex

I need to replace some non text characters in some automatically generated files with spaces.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.