mwaw Posted June 22, 2010 Share Posted June 22, 2010 I want to develop a PHP script that posts some data to a page on a different website and at the same time sends the user to that same page. If I were developing a script for use on http://domainA.com, and I wanted the user to post info and go to http://domainB.com, I could do this easily using simple HTML like this: On domainA.com I would write HTML like this: <form action="http://domainB.com/somepage.php" method="post"> <input type="hidden" id="dataA" name="dataA" value="A" /> <input type="hidden" id="dataB" name="dataB" value="B" /> <input type="submit" value="Send Data" /> </form> Once the user clicked on the submit button, the data would be sent, and the user would be taken to domainB.com/somepage.php. However, I want the whole thing to be automatic, so the user does not need to click on a submit button. I have just a very basic understanding of cURL. <> Is cURL the best library to use? If so, I would appreciate some tips on how to use it for this purpose. I don't need a complete script, just some pointers. <> If cURL isn't the best approach, I would appreciate some advice about a better approach. Just to clarify, I don't want output from http://domainB.com/somepage.php to be displayed on a page on http://domainA.com. I actually want the user (and their data) to go to http://domainB.com/somepage.php, just as if they had clicked on a submit button in an HTML form. Thanks! Mike Wilkinson Link to comment https://forums.phpfreaks.com/topic/205597-post-data-and-go-to-web-page/ Share on other sites More sharing options...
ChemicalBliss Posted June 22, 2010 Share Posted June 22, 2010 For what you want to do you would be better using Javascript to automatically submit the form. If you use PHP - (cURL), you will need to get the result of the post data (the HTML result page) and feed it to the user, but they will still be on your page and if they do not use complete URLs you could find that you need to do a lot of work to get it to work. cURL is mainly used to either blindly submit data, or retrieve data from another website to use on your own (like grabbing news links etc). Using Javascript you can, for example; Use a PHP page to generate a default form (in HTML) with a snippet of javascript in there that will automatically submit the form as soon as possible. The form can be filled with default values so the data can be dynamically added when you create the HTML page. Sort of like a redirect, but posting a form instead. eg; <?php $redirectpage = "http://somedomain.com/somepage.php"; $form = "<form name='autoform' method='post' action='".$redirectpage."'> <input type='hidden' name='somevariable' value='somevalue' /> <input type='hidden' name='somevariable2' value='somevalue2' /> <input type='hidden' name='somevariable3' value='somevalue3' /> </form>"; $htmlcode = "<html><head><title>Redirecting...</title></head><body onload='document.autoform.submit();'>".$form." <center>If this page has not redirected within 5 seconds please <a href='thispage.php'>click here to try again</a></body></html>"; ?> -cb- Link to comment https://forums.phpfreaks.com/topic/205597-post-data-and-go-to-web-page/#findComment-1075866 Share on other sites More sharing options...
Ruzzas Posted June 23, 2010 Share Posted June 23, 2010 Use javascript for the automatic redirect when for example onClick() Link to comment https://forums.phpfreaks.com/topic/205597-post-data-and-go-to-web-page/#findComment-1075899 Share on other sites More sharing options...
mwaw Posted June 23, 2010 Author Share Posted June 23, 2010 Thanks for the responses, and I have successfully used JavaScript for this sort of thing before. I may use it again on this project. I may also just send the info using GET and the PHP header command. Thanks again. Link to comment https://forums.phpfreaks.com/topic/205597-post-data-and-go-to-web-page/#findComment-1076147 Share on other sites More sharing options...
ChemicalBliss Posted June 23, 2010 Share Posted June 23, 2010 Well if you have access to the script your sending the user to, use cURL to post the data, and make the script your sending them to retrieve the information from the DB that was sent using cURL. If you use GET with a lot of information it will fail with an error of "URL too large" either on the server or in your browser. POST data can use an almost infinite amount of data (for uploading files etc). If you want a simpler solution without modifying your end script, use the example i provided above to implement into your script. -cb- Link to comment https://forums.phpfreaks.com/topic/205597-post-data-and-go-to-web-page/#findComment-1076292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.