For spoofed data submitted from a URL, the following code is first checked from the previous page source:
<?/*php method to prevent data submission outside the station * *
function Checkurl () {
$servername =$_server[' server_name '];
$sub _from=$_server["Http_referer"];
$sub _len=strlen ($servername);
$checkfrom =substr ($sub _from,7, $sub _len);
if ($checkfrom!= $servername) die ("Warning!)" You are submitting data from the outside! Please terminate immediately! ");
}
? >
This method only prevents URLs that are entered manually on the navigation bar.
In fact, as long as a link to the URL is constructed on the server (for example, by adding a hyperlink to a post) and then clicked, the check doesn't work at all.
At present, it is more reliable to transmit important data by post method.
You can insert some hidden text in the form to pass data.
Or use Ajax to submit data from the client to the server using the following method.
* * Create XHR Object
/function createxhr ()
{
if window. XMLHttpRequest) {
var ohttp = new XMLHttpRequest ();
return ohttp;
}
else if (window. ActiveXObject) {
var versions = ["MSXML2. xmlhttp.6.0 "," MSXML2. xmlhttp.3.0 "];
for (var i = 0; i < versions.length i++) {
try {
var ohttp = new ActiveXObject (versions[i));
return ohttp;
} catch (Error) {}}}
throw new error ("Your browser does not support ajax! ");
}
/* Use AJAX to transfer data to page page * *
function Ajaxpost (url,query_string= ')
{
var xhr;
XHR = CREATEXHR ();
Xhr.open (' POST ', url,false);
Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded; charset=gb2312 ");
Xhr.onreadystatechange = function () {if (xhr.readystate = 4) if (Xhr.status!=) return;
Xhr.send (query_string);
}