电脑安全

您当前的位置:主页 > 电脑安全 >

php 保存数据代码-网络编程

来源:[db:来源]标题:   数据    编辑:电脑技术全能网 时间:2019-09-22 06:21

原标题:php 保存数据代码-网络编程
   咱们用php来完成数据保留哦,看看吧,过滤一些分歧法的字符以及种种避免反复发内容的功效 <?phpinclude_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['an'])?$_POST['an']:''));$ip = get_real_ip();$time =date("Y-m-d");if(empty($mobile) || empty($email) || empty($name) || empty($an)){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','$an','$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>", //假如要间接肃清不保险的标签,这里能够留空 "/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("忠告!你正在从内部提交数据或间接拜访c.php文件!请马上停止!!"); }}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']);}?>本站原创www.dnjishu.com/phper/php.html

上一篇:zend历程 之 ZendFramework-1.0.3-网络编程

下一篇:没有了