Re: grabbing data from other peoples sites

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Perry, Matthew (Fire Marshal's Office) wrote:
I guess my real question is how to parse the output from someone else's
site.  Setting up the lookup procedure from data in my database and filling
their form with the address is the easy part.  How do I make their form
"submit", parse the output, store it, and then reuse it in another function?
I have never tried something like this before.
- Matthew
[snip]

just fyi - you should test this on your own site until it's working as you expect, then start poking at them - it's only proper, and you can debug better that way. You may want to see about setting a referrer as well, they may check for it. Lastly - if they require a cookie of some sort, you'll have to figure that bit out :) Should be doable, just need two requests/etc.

example modified from php manual user contrib notes for fsockopen ( joe at edwardsconsultants dot com (10-Aug-2003 08:56) original example )
//
oh - and it's untested by yours truly.
//
$proto = "http";
$host = "foobarfoobar.com";
$port = "80"; // or 443 for https
$path = "/where/on/their/site/lookup_backend.php";
$our_data = array ( "address" => "55 main street" );
$poststring = "";
// build our post
foreach ($our_data as $key => $val) {
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
if ($poststring != "") { $poststring = substr($poststring, 0, -1); }


// done with setup - now let's move on to the action
$fp = fsockopen($proto.'://'.$host, $port, $errno, $errstr, $timeout = 30);
if (!fp) {
	echo "$errstr ($errno)\n";
} else {
	// send request
	fputs($fp, "POST $path HTTP/1.1\r\n");
	fputs($fp, "Host: $host\r\n");
	fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
	fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
	fputs($fp, "Connection: close\r\n\r\n");
	fputs($fp, $poststring . "\r\n\r\n");
	// get response
	while(!feof($fp)) {
		*/
		todo - do something other than fgets with this.
		it would be better to get the whole response then close 	
		fp, then move on to doing what you need - instead of
		doing your database stuff right away.
		*/
		echo fgets($fp, 4096);
	}
	//close fp - we are done with it
	fclose($fp);
}

Cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux