Method One:
You can write code that deals with submitting data into a separate file, such as form.php.
<?php
if defined (' INSIDE ') {//to determine whether there is a defined INSIDE constant
//processing form
} else {
exit (' ERROR ');
}
?>
Then, on the page that submits the form, define the INSIDE constant, and the constant value doesn't matter
define (' INSIDE ', ' TRUE ');
Then, to determine whether there is a commit, if submitted, then
include ' form.php ';
======================================================================================= Method two:
<?php
if (php_version< ' 4.1.0 ') {$_server = $HTTP _server_vars;}
if (IsseT ($_server["http_referer"])) {
//For some browsers may not have http_referer, so make 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 "<script language=" JavaScript ' >window.alert (' The data source is wrong, this station does not receive the data from the receiving terminal! '); Window.opener=self;window.close ();</script> ";
exit;
}
}
?>
This method is not absolutely safe, Because Http_referer can be forged, can only be a gentleman but can not prevent the villain, but under normal circumstances already enough.