开发者

POST and GET methods

I want to transfer a data from one webpage to another page. But I don't want to use the <form method="post"> tag because there are no forms in my webpage. Just some sensitive data is there which needs to be transferred to other page.

Please answer the following questions:

  1. What are the ways to transfer data from one page to another?
  2. What are the ways to transfer data from one page to another without using <form> tag in HTML?
  3. H开发者_运维问答ow can another PHP (or ASP) page can read the data which was sent to it by another page?


I don't want to use the <form method="post"> tag because there are no forms in my webpage

That is not a good reason to avoid using a form. You can add one.

What are the ways to transfer data from one page to another?

  1. Through the URI (in a query string)
  2. As part of the request body (a POST request)
  3. Via cookies (which you can set with JS)
  4. Via various local storage systems

Use a query string if the data needs to be bookmarkable. Use a POST request (with a form) if it makes changes on the server (e.g. adds or edits a database entry). Use a cookie (preferably set via HTTP after using methods 1 or 2) if the data needs to persist throughout the site. Use local storage for web applications that need to function offline.

What are the ways to transfer data from one page to another without using tag in HTML?

As above, but discount post requests (unless you make them using JavaScript and XMLHttpRequest).

How can another PHP (or ASP) page can read the data which was sent to it by another page?

With local storage, it can't. All the other data is available through the server environment ($_POST, $_GET and $_COOKIE in PHP, for example).


  1. You could use a hidden input i.e. <input name="secret" type="hidden" value="superSecretData" />

  2. You could create a random element which contains the data i.e. <div style="display: none">SuperSecretData</div>

3a. In the case of the former in php it would just be a matter of accessing $_POST['secret']

3b. In the case of the later you would need to use javascript of something of that sort to take the random element and send it along with the page.

Hope this helps


1.) EasyXDM using postMessage if available, hash tags, or flash

2.) same as 1

3.) again you can use EasyXDM

if you open the other page with window.open or similar, or iframes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜