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
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

Link to comment
Share on other sites

//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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.