0

I'm building a website and I need to login to another site and take some info from there. the Problem is that the other site requires a user-name and a password (which I have of course) at it's login page. How can I enter my user-name & password and then pass to the second page to get the info ? I'm trying to do it via php but I just read that mayby curl is required..

thanks !

Witterquick
  • 6,048
  • 3
  • 26
  • 50
  • Related: [PHP Site Scraping With a Secure Login](http://stackoverflow.com/questions/4327908/php-site-scraping-with-a-secure-login) – miku Jun 13 '11 at 15:04
  • possible duplicate of [Login to remote site with PHP cURL](http://stackoverflow.com/questions/3008817/login-to-remote-site-with-php-curl) – Michael Berkowski Jun 13 '11 at 15:04
  • I did search here before posting it, and didn't found any answer but I also didn't see what you posted here. thanks ! – Witterquick Jun 13 '11 at 15:27

1 Answers1

2

Use cURL!

Create a page on your remote page that returns the information (i'd recommend using xml as your format) that you want then grab it like this from the site requesting information.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.yourRemoteWebsite.com/mysecretinformation.php");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=Roee84&password=yourPassword');

$myInfo = curl_exec($ch)

At that point, $myInfo will have whatever information you sent from the other side.

if you end up using xml, check out http://php.net/manual/en/book.simplexml.php for easy parsing.

castis
  • 8,154
  • 4
  • 41
  • 63