Jump to content

Parsing remote page and outputting


A3sthetix

Recommended Posts

Here is a general idea of what I want to do:

  • HTML Form is submitted by remote user using POST method
  • Variables are received by 'search.php'
  • Script within 'search.php' will POST same variables to a remote (3rd party) website ???
  • Script downloads the resulting HTML page
  • Script parses HTML page and displays relevant data (ie. a specific table)

 

I'm stuck at the part with the ??? -- how would I get PHP to POST the user's vars to get the page returned? I know how to do this if I were using a GET method, but this is not an option.

 

Thanks in advance for your help!

Link to comment
https://forums.phpfreaks.com/topic/75946-parsing-remote-page-and-outputting/
Share on other sites

Using curl you should be able to do that.

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL,"http://www.someothersite.com");

//add post stuff here
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");
         
$buffer = curl_exec ($ch);

curl_close ($ch);

echo '<pre>'.htmlentities($buffer ).'</pre>';

Not sure if this will work as is. I haven't tested it. But it should give you a start.

 

EDIT: you will need curl installed

//add post stuff here
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");
         
$buffer = curl_exec ($ch);

curl_close ($ch);

echo '<pre>'.htmlentities($buffer ).'</pre>';

 

Okay, that's a start. Thanks for your quick replies. I guess for the line reading:

curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");

I'll have to use http_build_query and drop the var in there. I'll have to check on curl. I know I can install it on my WAMP development server, but I'm not sure about my client's server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.