我对 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>';    
    }
}
?>