我真的对以下问题感到绝望: 我想设置一个限制人们注册这个脚本(16)。好吧,我尝试和搜索,我放弃了!有人知道如何设置它只是简单地编辑脚本,以便我可以复制粘贴它。
这是脚本
<?php
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$action = isset($_POST['action']) ? $_POST['action'] : '';
$mysql_server = 'X';
$mysql_username = 'X';
$mysql_password = 'X';
$mysql_database = 'X';
$mysql_table = 'LOL';
$success_page = 'X';
if ($action == 'signup')
{
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
if ($newpassword != $confirmpassword)
{
$error_message = 'Password and Confirm Password are not the same!';
}
else
if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newusername))
{
$error_message = 'Team name is not valid, please check and try again!';
}
else
if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newpassword))
{
$error_message = 'Password is not valid, please check and try again!';
}
else
if (!ereg("^.+@.+\..+$", $newemail))
{
$error_message = 'Email is not a valid email address. Please check and try again.';
}
$db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
mysql_select_db($mysql_database, $db);
$sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
$result = mysql_query($sql, $db);
if ($data = mysql_fetch_array($result))
{
list($username, $password, $email, $fullname) = explode('|', trim($line));
if ($newusername == $username)
{
$error_message = 'Team name already used. Please select another username.';
}
}
if (empty($error_message))
{
$crypt_pass = md5($newpassword);
$sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 1)";
$result = mysql_query($sql, $db);
mysql_close($db);
$mailto = $newemail;
$subject = 'X';
$message = 'X';
$message .= "\r\nX";
$message .= "\r\n ";
$message .= "\r\nTeam name for the upcoming tournament: ";
$message .= $newusername;
$message .= "\r\nYour password: ";
$message .= $newpassword;
$message .= "\r\n ";
$message .= "\r\n ";
$message .= "\r\nX";
$message .= "\r\nX";
$header = "From: X"."\r\n";
$header .= "Reply-To: X"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($mailto, $subject, $message, $header);
header('Location: '.$success_page);
exit;
}
}
}
?>
答案 0 :(得分:0)
在对用户进行任何形式的验证之前,请运行查询:
SELECT COUNT(*) AS 'num_users' FROM users_table;
然后获取'num_users'列,并且;
if ($row['num_users'] >= $max_users)
然后向用户显示相应的文本并退出脚本(或将用户重定向到某个适当的抱歉页面)。
答案 1 :(得分:0)
请按照以下步骤操作:
1)取一个变量来定义你的极限。 我带
$limitData = 16
2)查询用户表
$result = mysql_query("SELECT * FROM USERS");
$num_rows = mysql_num_rows($result);
3)这个$ num_rows会告诉你已经注册了多少。 现在插入新数据的最后一步,你必须放一个条件
if($limitData > $num_rows)
{
//put your insert query in this section
}