<form action="somesite.com" name="somename">
<inpu开发者_高级运维t type="text" name="data" value="">
</form>
If I try to execute this code in my local system, the value with the name 'data' will be transferred to the site 'somesite.com'
Is it the right way to transfer the data to any other web site which already exists? What will happen to that data (if successfully transferred to somesite.com)?
In general, what exactly happens to the value of 'data' if we dont use that value in any part of our script?
Hope I am clear???
If data
is not processed by the script running on the server receiving the HTTP Request, it is gone afterwards.
Your browser creates an HTTP request with the form data when you submit the form and sends it to the webserver specified in the form action. The webserver just knows how to handle the HTTP Request as such. Your PHP scripts have to know how to handle the data within the HTTP Request. HTTP is a stateless protocol, so there is nothing stored by the webserver.
Note: technically, when receiving GET requests with added params, you might find them in your webserver's access log, so they are stored, but it's not like you would reuse them from there.
Have a look at the Firefox addon Tamper Data to see what happens when you submit a form. If you want to use IE, try Fiddler.
As to whether you should use GET or POST as a form method, stick to the W3Cs recommendation:
1.3 Quick Checklist for Choosing HTTP GET or POST
* Use GET if: o The interaction is more like a question (i.e., it is a safe operation such as a query, read operation, or lookup). * Use POST if: o The interaction is more like an order, or o The interaction changes the state of the resource in a way that the user would perceive (e.g., a subscription to a service), or o The user be held accountable for the results of the interaction.
However, before the final decision to use HTTP GET or POST, please also consider considerations for sensitive data and practical considerations.
As you don't have a submit button inside your form
, the user will have difficulties submitting it. But if this form is submitted somehow, the browser will redirect to the following address: http://somesite.com/?data=somevalue
. As you can see the value will be sent with a GET
request which is the default. If you don't use the data
in any part of the script that's supposed to handle the form submission, then you've probably wasted some bytes of bandwidth, but other than that not much will happen.
Form works with any url as action, if it's on another website, you must provide the absolute url :
http://www.somesite.com
It's pure html, it has nothing to do with php. Of course, as the data is sent to another website you can't handle it in your script. It's up to the target website.
精彩评论