PHP Automatic Form Action
Hello,
I'm trying to prepare a php page that gets data by post, processes it and should redirect the visitor to another page, to which we also send other data by post. As I can't use a simple HTML Form, I tried the fsockopen, but it only gives me back the result and doesn't GO to that page. How should I do this? Thanks a lot. David |
You have basically two options.
Your PHP script can act as a reverse proxy, and do the POST request on behalf of the client, echoing the response to the client. You could do this using fopen() alone, if you construct the necessary HTTP request yourself, and your PHP configuration has allow_url_fopen enabled. In any case, note that you need to output the headers (everything before first empty line) using header(). You could also use the PECL extension pecl_http to do the reverse proxy query. The common solution is to generate an intermediate page, which will be shown to the user. This page will contain the a hidden form, with values set in your PHP script. The form will be automatically submitted by a simple Javascript onload handler in the body element; it only needs to call the submit() method on the hidden form. There are major differences between the limitations of the two methods. The former method can forward files in the POST request, while it is extremely difficult in the latter; you may have to modify the second POST handler to get file upload to work at all using the latter method. The latter method will also show the user an intermediate page, unless you use a hidden frame to target the initial POST request at. There may be other considerations too; for example, if there is a lot of data, the latter method will effectively transfer it three times during the process between the client and the servers, while the former method will transfer it only once between the client and the first server, and once between the two servers. In general, if your POST data may contain file upload fields, go with the first method. If you know your POST data will not contain file upload fields, and relying on Javascript at the client end is not a problem, go with the second method. Hope this helps. |
Quote:
Quote:
Thanks. |
php + JavaScript
I finally found the way to do it, using JavaScript:
Code:
<?php |
All times are GMT -5. The time now is 08:11 PM. |