Jump to content


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


match a variable to a rand variable?

Recommended Posts

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.


# 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
echo "Passwords do not match.";

// Check if verification code is correct
echo "Verification code is incorrect.";

// 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
$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
echo "<script>
<form action="register.php" method="POST">
<table width="352" border="0">
    <td width="128">Username:</td>
    <td width="214"><input type="text" name="username"></td>
    <td><input type="password" name="password"></td>
    <td>Confirm Password: </td>
    <td><input type="password" name="cpassword"></td>
    <td>Email Address: </td>
    <td><input type="text" name="email"></td>
    <td>Hide Email? </td>
    <td><select name="hideemail">
<option name="1">Yes</option>
<option name="0">No</option>
    <td>Verification code: </td>
    <td><?php echo $key; ?></td>
    <td>Confirm code: </td>
    <td><input type="text" name="vercode">
<Br />
<input type="submit" name="submit" value="Register">

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites


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.