Home > Backend Development > PHP Tutorial > PHP checks whether form submission comes from this site_PHP Tutorial

PHP checks whether form submission comes from this site_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:52:35
Original
1160 people have browsed it

Method 1:
You can write the code that handles submitted data into a separate file, such as form.php. 
if (defined(’INSIDE’)) {//Determine whether the INSIDE constant is defined
//Process the form
} else else {
exit('error');
}  
?>
​  
Then, first define the constant INSIDE on the page where the form is submitted. The value of the constant does not matter.
define(’INSIDE’, ’TRUE’);
​  
Next, determine whether there is submission, if submitted, then
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 this 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 "

Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template