Jump to content


Photo

match a variable to a rand variable?


  • Please log in to reply
1 reply to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 24 July 2006 - 08:00 AM

Well I have a verification code that needs to be confirmed by the user, and the first $key is a random 6 digit code, and when it checks if they entered the right one, it checks for another 6 digit code. Any idea how to make the second $key match the first $key so it can be verified.

<?php

# ini_set('error_reporting', E_ALL);
			
// Include necessary files
require "includes/config.php";
require "includes/class_core.php";
require "includes/functions_randKeys.php";

// Generate verification code
$key = randKeys(6); 

// Make sure all required fields are correct
		if(isset($_POST['submit']) && !empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['cpassword']) && !empty($_POST['email']))
			{

// Check the users IP address for administrators future use
$ipaddress = $_SERVER['REMOTE_ADDR'];
	
// Define POST variables
		$username = $core->cleanstr($_POST['username']);
		$password = $core->cleanstr($_POST['password']);
		$cpassword = $core->cleanstr($_POST['cpassword']);
		$email = $core->cleanstr($_POST['email']);
		$hideemail = $core->cleanstr($_POST['hideemail']);
		
		$vercode = $core->cleanstr($_POST['vercode']);
		
		
// Check if passwords match 
		if($password!=$cpassword)
			{
				echo "Passwords do not match.";
				die();
			}  

// Check if verification code is correct			
		if($vercode!=$key)
			{
				echo "Verification code is incorrect.";
				die();
			}  
			
// Encrypt password to prepare for it's insertion to the DB
				$encrypt_pass = $core->encrypt($password);

// Insert user details into `members` table

/* FOR TESTING PURPOSES WE ARE USING ONLY members, on release we MUST use
{$TABLE_PREFIX}_tblname 
*/
					$sql = "INSERT INTO members (`id`, `username`, `password`, `email`, `hideemail`, `vercode`, `ipaddress`) VALUES ('', '$username', '$password', '$email', '$hideemail', '$vercode', '$ipaddress')";
					$sqlr = mysql_query($sql) or die(mysql_error());
						
// Redirect to home page if data is submitted
	if($sqlr)
		{
			echo "<script>
			window.location=\"index.php\"
			</script>
			";
			}
		}
?>
<form action="register.php" method="POST">
<center>
<table width="352" border="0">
  <tr>
    <td width="128">Username:</td>
    <td width="214"><input type="text" name="username"></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input type="password" name="password"></td>
  </tr>
  <tr>
    <td>Confirm Password: </td>
    <td><input type="password" name="cpassword"></td>
  </tr>
  <tr>
    <td>Email Address: </td>
    <td><input type="text" name="email"></td>
  </tr>
  <tr>
    <td>Hide Email? </td>
    <td><select name="hideemail">
<option name="1">Yes</option>
<option name="0">No</option>
</select></td>
  </tr>
  <tr>
    <td>Verification code: </td>
    <td><?php echo $key; ?></td>
  </tr>
  <tr>
    <td>Confirm code: </td>
    <td><input type="text" name="vercode">
	<Br />
	<input type="submit" name="submit" value="Register">
	</td>
  </tr>
</table>
</center>
</form>


#2 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 24 July 2006 - 10:07 AM

i dont get what your saying..  but i think i can help if this is what your trying to get at...

in this area
  <td>Verification code: </td>
    <td><?php echo $key; ?></td>
do this
  <td>Verification code: </td>
    <td><?php echo "$key <input type='hidden' value='$key' name='key' />"; ?></td>
that will send a $_POST variable to the page that your form calls, with the variable KEY set with the key it displayed on the screen. so just call that post variable on your page and check it against what they typed.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users