Blogger Information
Blog 1
fans 0
comment 0
visits 1751
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
织梦自定义表单验证手机,获取IP、时间、URL,限制留言次数
当时惊个呆的博客
Original
1755 people have browsed it

QQ截图20180523155935.png

首先自定义表单须有这四个字段:IP,domain(域名),time(留言时间),telephone(检测手机号)

思路是这样的,如果不先检测手机号码,随便输入一个号码之后提交,虽然没有写入数据库,但是浏览器缓存已经记录你提交了一次了。再次输入正确的手机号码,会提示你已经输入了。你要清除缓存重新留言,所以先检测手机号码

先检测手机号码是否正确

//验证手机号
		if(!preg_match("/^1[3456789]\d{9}$/", $telephone))
        {
            // showMsg('手机号不对,请重新输入', '-1');
            echo "<script>alert('手机号不正确,请重新输入'); history.go(-1)</script>";
            exit();
        }
        //验证手机结束

QQ截图20180523154419.png


获取IP地址和留言时间

//获取IP地址和留言时间
                    if($fieldinfo[0] == 'ip')
                    {  
                    ${$fieldinfo[0]}=GetIP();  
                    }  
                    if($fieldinfo[0] == 'time')  
                    {  
                    ${$fieldinfo[0]}=date("Y/m/d H:i:s");  
                    }
                    //结束获取IP地址和留言时间
                    if($fieldinfo[0] == 'domain'){${$fieldinfo[0]}=$_SERVER['HTTP_REFERER'];}
                    //结束获取URL

QQ截图20180523154338.png


检测用户是否已经提交过表单

//检测游客是否已经提交过表单 
        if(isset($_COOKIE['VOTE_MEMBER_IP']))  
        {  
            if($_COOKIE['VOTE_MEMBER_IP'] == $_SERVER['REMOTE_ADDR'])  
            {  
                // ShowMsg('您已经填写过表单啦','-1');
                echo "<script>alert('您已经填写过表单啦!招商经理会尽快与您取得联系'); history.go(-1)</script>";
                exit();  
            } else {  
                setcookie('VOTE_MEMBER_IP',$_SERVER['REMOTE_ADDR'],time()*$row['spec']*3600,'/');  
            }  
        } else {  
            setcookie('VOTE_MEMBER_IP',$_SERVER['REMOTE_ADDR'],time()*$row['spec']*3600,'/');  
        } 
        //结束检测

QQ图片20180523154747.png

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments