How does PHP determine whether a php page is submitted from <form> or directly entered from the address bar?

Source: Internet
Author: User
For example, how does localhostyb1Homecurdcreate determine whether to submit or enter it in the address bar? Actually it means that after I submit it once, it will go to localhostyb1Homecurdcreate, localho...

In this example, how does one determine whether the request is submitted or entered in the address bar through http: // localhost/yb1/Home/curd/create?

In fact, this means:
After I submit it once, it will go to http: // localhost/yb1/Home/curd/create,
Http: // localhost/yb1/Home/curd/create,

If you press F5 to refresh directly, an error will occur. when I press F5, I want to know whether it was from post or I refreshed it directly from this page ..

Reply content:

In this example, how does one determine whether the request is submitted or entered in the address bar through http: // localhost/yb1/Home/curd/create?

In fact, this means:
After I submit it once, it will go to http: // localhost/yb1/Home/curd/create,
Http: // localhost/yb1/Home/curd/create,

If you press F5 to refresh directly, an error will occur. when I press F5, I want to know whether it was from post or I refreshed it directly from this page ..

Determined by referer; source address

I think you may need to avoid repeated forms. you can add token.

On the create page, use$_SERVER['REQUEST_METHOD']And the value isgetIt indicates that the page is refreshed,postThe description is submitted by form.

After POST processing is complete, the backend initiates a redirection to redirect to a new URL, so that the user has no chance to refresh the submission.

-- Improve

The possible pseudocode may be:

If ($ _ SERVER ['request _ method']! = 'Post') {// process non-POST logic, such as return ;} // process POST requests submitted by users // Create users, add articles, etc // after processing, redirect requests can be newly created pages by POST requests, for example, the user Center, article details, etc. // or even the source page initiated by the POST request. in this case, you can consider processing user input backfilling, or, a message header indicating success or failure ('Location:/path/to/location') is displayed ');

When you click the form to submit, record a tag, submit it, and delete the tag. you can judge whether there are post and get types. the address bar that can also be judged is a get

You can read the data in the address bar once for monitoring, but this method does not cure the problem. you can also forge the post or get method in other ways.
It is possible to add hidden domains.

You should use tp. tp can.

if(IS_POST){    echo 1;}else {    echo 0;}

If your form submission method is POST, it is also POST request when you press F5 to refresh again.
It is recommended that the subject understandIdempotent request.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.