Jump to content

no variable $test after secund submit


GSW
 Share

Recommended Posts

Hello,

I'm making a php script to reset AD account.

The first form is for collect the users information, and send a mail if the user is locked. In the mail there is a random number ($test).

A second form  appears for enter the code ($code).  If $code == $test then the AD Account get unlocked.

The last one don't work, because $test is empty.

 

What am I doing wrong? and if you can improve the script let me know.

Best regards,

GSW

 

 

functions.php reset.php

Link to comment
Share on other sites

  • 3 weeks later...

Have you checked if this returns the unid() value?

echo "line 106 &nbsp" . $test . "<br/>";

Just double check if everything goes through. Simplified your code for testing and worked for me.

<?php
function Send_mail($to){
	return uniqid();	
}
$test = Send_mail("1");
	if (isset($_POST['code']) && !empty($_POST['code'])){
        $code = htmlspecialchars ($_POST['code']);
	}
// I don't get echo good, because $test is empty.
	if (!empty($code)){
		if ($code == $test){
			echo "good";
		}
		else{
			echo "bad";
			echo "<br>";
			echo "line 149 &nbsp" . $code;
			echo "<br>";
			echo "line 151 &nbsp" . $test;
		}
    }
	if (!empty($test)){
		echo "line 156 &nbsp" . $test;
		?>
			<div class="code">
				<form method="post">
					Code: <input type="text" name="code">
					<input type="submit">
				</form>
			</div>
			
		<?php
	}
 //END for loop
?>

Also noticed that what you're trying to do is not possible with method you're currently doing. Every time you do post/get action it will get new unique id and wont match the form code (unless you guess the uniqid). Instead store the uniqid to php session or database to make it work and simply remove it after.

Edited by Mudsaf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...