Php: save data code-PHP source code

Source: Internet
Author: User
Let's use php to save data. Let's take a look and filter out invalid characters and various features to prevent repeated content Sending. We use php to save data. Let's take a look, filter invalid characters and various features to prevent repeated content Sending

Script ec (2); script

Include_once ("inc/connect. php ");
Stop_outside_post ();
$ Email = php_sava (addslashes (isset ($ _ POST ['email '])? $ _ POST ['email ']: '');
$ Mobile = php_sava (addslashes (isset ($ _ POST ['mobile'])? $ _ POST ['mobile']: '');
$ Name = php_sava (addslashes (isset ($ _ POST ['name'])? $ _ POST ['name']: '');
$ An = php_sava (addslashes (isset ($ _ POST ['any'])? $ _ POST ['any']: '');
$ Ip = get_real_ip ();
$ Time = date ("Y-m-d ");
If (empty ($ mobile) | empty ($ email) | empty ($ name) | empty ($ )){
Die ('submit = false ');
} Else {
$ Tsql = "Select * from lzlj_an where ip = '$ ip '";
$ R = mysql_query ($ tsql );
If (mysql_num_rows ($ r )){
Die ('submit = false ');
} Else {
$ SQL = "Insert into lzlj_an (mobile, email, name, an, ip, dtime) value ('$ mobile', '$ email', '$ name ', '$ any',' $ ip', '$ Time ')";
Mysql_query ($ SQL) or die ('submit = false ');
Die ('submit = true ');
}
}

Function php_sava ($ str)
{
$ Farr = array (
"/S + /",
"/<(/?) (Script | I? Frame | style | html | body | title | link | meta |? | %) ([^>] *?)> /IsU ",
"/(<[^>] *) On [a-zA-Z] + s * = ([^>] *>)/isU ",

);
$ Tarr = array (
"",
"<\ 1 \ 2 \ 3>", // If You Want To directly clear insecure labels, leave it blank.
"\ 1 \ 2 ",
);

$ Str = preg_replace ($ farr, $ tarr, $ str );
Return $ str;
}

Function stop_outside_post (){
$ 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 outside or directly accessing the c. php file! Please terminate now !! ");
}
}

Function get_real_ip (){
$ Ip = false;
If (! Empty ($ _ SERVER ["HTTP_CLIENT_IP"]) {
$ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
}
If (! Empty ($ _ SERVER ['HTTP _ X_FORWARDED_FOR ']) {
$ Ips = explode (",", $ _ SERVER ['HTTP _ X_FORWARDED_FOR ']);
If ($ ip) {array_unshift ($ ips, $ ip); $ ip = FALSE ;}
For ($ I = 0; $ I <count ($ ips); $ I ++ ){
If (! Eregi ("^ (10 | 172.16 | 192.168).", $ ips [$ I]) {
$ Ip = $ ips [$ I];
Break;
}
}
}
Return ($ ip? $ Ip: $ _ SERVER ['remote _ ADDR ']);
}
?>
Original Site www.111cn.net/phper/php.html

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.