Jump to content

Post Data and Go to Web Page


mwaw

Recommended Posts

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

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-

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-

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.