views:

75

answers:

1

Hi Everyone:

I'm not quite sure how to describe this in words without making it overly complex, so here is basically what I want to happen:

  1. The user goes to my website, let's say: www.example.com/
  2. The server goes to another website, example2.com, which has a field where their users should enter their username and password
  3. The server inputs the username and password automatically, and then gets redirected to a "user section" of the site.
  4. The server clicks on one of the links on the sidebar, and gets sent to another page "user section".
  5. Then, the site grabs all of the content on this page, and displays it on example.com

The reason I am attempting to do this is to create an RSS feed out of a website that has a username and password part where the user has to log in. I have not seen a RSS creating website that enables you to do this, which is why I am trying to accomplish it this way. However, if anyone knows of a RSS website that will enable you to do this, that would also be great.

Thanks for any help!

+6  A: 

It sounds like you might be looking for cURL and cookiejar:

http://curl.haxx.se/libcurl/php/examples/cookiejar.html

This will allow you to programmatically login to a site, keep a session open, and then access the login protected content. Once you get the page contents, then you can use DomDocument (http://us2.php.net/manual/en/domdocument.loadhtml.php) to access the content you need and turn it into RSS data.

Edit: if the website uses form keys, like many do, this will require extra work to extract the form key from the login page and add it to the login POST

Mark
Hi Mark: Nice find! However, I am not quite sure if I know how to make that work with the website I am attempting to login to. Do you set the line: curl_setopt($ch, CURLOPT_URL[...] to the URL of your login page and the line: curl_setopt($ch, CURLOPT_POSTFIELDS[...] to the ID's and values of the fields? If so, it doesn't quite seem to be working for me.
PF1
Yes those are the correct places to set the values. You may need to check the source code of the login page to see if they are using any form keys or extra hidden fields. Also, some sites may check the referrer. So you will need to fake the http referrer with:curl_setopt ($ch, CURLOPT_REFERER, "http://www.domain.com/loginpage");
Mark
PF1
add this: curl_setopt($sh, CURLOPT_FOLLOWLOCATION, true);
Mark
Okay, I added it and it works great now. However, it still doesn't login to the page - just redirects it to the login page.
PF1