Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试将php脚本从阻止相同的ip更改为阻止相同的ID号_Php_Scripting - Fatal编程技术网

尝试将php脚本从阻止相同的ip更改为阻止相同的ID号

尝试将php脚本从阻止相同的ip更改为阻止相同的ID号,php,scripting,Php,Scripting,我对PHP非常陌生,仍在努力学习它的“细节”(自学)我有一个请愿网站,我有一个朋友为其开发了一个代码,阻止相同的ip多次签名 这个特殊的申请被发送到有多个使用相同IP的签名者的办公室,因此我需要将代码从阻止重复IP更改为阻止签名者提供的重复“GLVAR”号。我有数据库设置,但我只是不知道在哪里确切地改变编码,使这项工作 此外,我正在尝试将签名者提交的信息发送到我的电子邮件地址,以获得额外副本。我知道这应该很简单,但正如我所说的,我是自学成才,非常新,所以任何帮助都将不胜感激。非常感谢您抽出时间

我对PHP非常陌生,仍在努力学习它的“细节”(自学)我有一个请愿网站,我有一个朋友为其开发了一个代码,阻止相同的ip多次签名

这个特殊的申请被发送到有多个使用相同IP的签名者的办公室,因此我需要将代码从阻止重复IP更改为阻止签名者提供的重复“GLVAR”号。我有数据库设置,但我只是不知道在哪里确切地改变编码,使这项工作

此外,我正在尝试将签名者提交的信息发送到我的电子邮件地址,以获得额外副本。我知道这应该很简单,但正如我所说的,我是自学成才,非常新,所以任何帮助都将不胜感激。非常感谢您抽出时间

<?php
include('database/config.php');
include('database/database.php');

$err = '';

if(isset($_POST['submit'])){        

    $first = addslashes(trim($_POST['first'])); 

    $last = addslashes(trim($_POST['last']));   

    $glvar = addslashes(trim($_POST['glvar']));

    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; 
    //echo $ip;

     if(($first!='')&& ($last!='')&& ($glvar!='')){ 

        $database = new Database(HOST, DATEBASE, USERNAME, PASSWORD);   

        $allUsers = $database->select('user','ip','*',"ip = '".$ip."'");
        //echo $ip;     

        $checkIp = 0;           
    $checkIp = count($allUsers);    

        $userData = array(              
            'first_name' => $first, 
            'last_name' => $last,               
            'glvar_id' => $glvar,       
            'ip' => $ip,        

        );      

        if(!$checkIp) {         

            $database->insert('user',$userData);        

            header('location:thank-you.html');      

        }    else  $err.='<p style="color:red">Ooops! You have already signed the petition</p>';        

    } else {    

        if($first=='') $err.='<p style="color:red">Your first name not empty</p>';  

        if($last=='') $err.='<p style="color:red">Your last name not empty</p>';    

        if($glvar=='') $err.='<p style="color:red">Your GLVAR ID not empty</p>';    

    }

}

?>

您应该查询数据库中的
glvar
,而不是IP:

它可能是这样的,这取决于数据库中glvar_id列的外观

$allUsers = $database->select('user','glvar_id','*',"glvar_id = '".$glvar."'");
//echo $ip;

$checkglvar = 0;
$checkglvar = count($allUsers);
如果您希望在成功时发送邮件,那么您需要为work配置php邮件功能,并将其添加到此处:

if(!$checkIp) {

    $database->insert('user',$userData);

    mail("to@me.com", "Subject", "message");

    header('location:thank-you.html');

}

很抱歉,我不知道你在问什么。看看生成php请求的表单会很有帮助,特别是GLVAR的格式是什么?您如何确保它是唯一的?GLVAR ID号是我们所在州为该特定组织提供的ID号。每个人的身份证在这方面都是独一无二的。我只需要代码来搜索数据库中的重复ID,如果可能的话阻止提交。谢谢。。。我现在就试试