PHP checks whether form submission is from this site _ PHP Tutorial

Source: Internet
Author: User
PHP checks whether the form submission is from this site. Method 1: You can write the code for processing submitted data to a separate file, such as form. php .? Phpif (defined (INSIDE) {determine whether there is a defined INSIDE constant processing form} el Method 1:
You can write the code for processing submitted data to a separate file, such as form. php.
If (defined ('Inside ') {// determines whether a defined INSIDE constant exists.
// Process the form
} Else {
Exit ('error ');
}
?>

Then, define the constant value INSIDE on the page where the form is submitted.
Define ('Inside ', 'true ');

Then, determine whether a request is submitted. If yes
Include 'form. php ';

========================================================== ========================================================== ======= Method 2:

If (PHP_VERSION <'4. 1.0 ') {$ _ SERVER = $ HTTP_SERVER_VARS ;}
If (isset ($ _ SERVER ["HTTP_REFERER"]) {
// Some browsers may not have HTTP_REFERER, so make such a judgment.
$ Servername = $ _ SERVER ['server _ name'];
$ Sub_from = $ _ SERVER ["HTTP_REFERER"];
$ Sub_len = strlen ($ servername );
$ Checkfrom = substr ($ sub_from, 7, $ sub_len );
If ($ checkfrom! = $ Servername)
{
Echo"

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.