我是非常新的PHP,並仍在嘗試學習「來龍去脈」(自學)我有一個請願網站,我有一個朋友開發一個代碼,阻止相同的IP從簽名不止一次。試圖改變一個PHP腳本阻止相同的IP到blockingidentical ID號碼
這個特定的請願書被髮送到使用相同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>';
}
}
?>
我很抱歉,我不知道你的要求的。 – user2507414
看到生成php請求的表單會很有幫助 - 特別是GLVAR的格式是什麼?你如何確保它是獨一無二的? – Floris
GLVAR ID號碼是由我們爲此特定組織而定位的州提供的ID號碼。每個人的身份證在這方面都是獨一無二的。我只需要代碼來搜索數據庫中的重複ID並在可能的情況下阻止提交。 – user2507414