A3sthetix Posted November 3, 2007 Share Posted November 3, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/75946-parsing-remote-page-and-outputting/ Share on other sites More sharing options...
einz Posted November 3, 2007 Share Posted November 3, 2007 PHP doesn't have builtin function to send POST data. You can construct HTTP header on your own, and then send to server, or use something like http_build_query+stream_context_create+fopen. Quote Link to comment https://forums.phpfreaks.com/topic/75946-parsing-remote-page-and-outputting/#findComment-384417 Share on other sites More sharing options...
Daukan Posted November 3, 2007 Share Posted November 3, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75946-parsing-remote-page-and-outputting/#findComment-384422 Share on other sites More sharing options...
A3sthetix Posted November 3, 2007 Author Share Posted November 3, 2007 //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. Quote Link to comment https://forums.phpfreaks.com/topic/75946-parsing-remote-page-and-outputting/#findComment-384425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.