Jump to content

Prevent resubmitting of form on refresh


rockinaway

Recommended Posts

If it will make any sense on it's own:

 

// We want to prevent quick signups
	$query = $db->query('SELECT joined
							FROM members
							WHERE ip_address = "'.$_SERVER['REMOTE_ADDR'].'"');


	// Have they JUST registered?  
	if ($db->num_rows($query) > 0) 
	{
		$t = $db->fetch_assoc($query);
		echo 'yes';

		echo time().'<br />';
		echo $t['joined'].'<br />';

		$last_signup = (time() - $t['joined']);
		echo $last_signup;
		if ($last_signup < 120) $core->error('Error', 'A registration has recently occurred');
	}

	// Trim and clean vars
	$fname = $core->cleanVar(trim($_POST['fname']));
	$lname = $core->cleanVar(trim($_POST['lname']));
	$password = $core->cleanVar(trim($_POST['password']));
	$email = $core->cleanVar(trim($_POST['email']));
	$sex = $_POST['sex'];
	$dob = $_POST['birth_day'].$_POST['birth_month'].$_POST['birth_year'];

	// Create salt and hash password
	$salt = $core->create_salt();
	$hash_pass = hash('sha256', $salt.$password);

	// Generate an activation code for the user
	$code = $core->keygen(20);

	// Add the user to the database
	$db->query('INSERT INTO members
				(first_name, last_name, password, salt, ip_address, email, joined, last_visit, sex, dob, group_id, status, code)
				VALUES
				("'.$fname.'", "'.$lname.'", "'.$hash_pass.'", "'.$salt.'", "'.$_SERVER['REMOTE_ADDR'].'", "'.$email.'", "'.time().'", "'.time().'", "'.$sex.'", "'.$dob.'", "1", "0", "'.$code.'");');

Why are you potentially grabbing multiple results? I told you before you should be checking based on dateline as well.

 

<?php
// We want to prevent quick signups
if ($db->query('
SELECT joined
FROM members
WHERE ip_address = "' . $_SERVER['REMOTE_ADDR'] . '"
	AND joined >= ' . (time() - 3600) . ' # Current time minus an hour. Can change this value to whatever you want.
LIMIT 1
')
{
$core->error('Error', 'A registration has recently occurred');
}
?>

 

Much cleaner code. More efficient as well.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.