这有点难以解释。使用图片可能会有所帮助!
1.用户提交表单,简单。
2.正在设置会话,并显示已设置的会话变量。
3.如果用户输入验证码错误或输入正确并继续到下一页,则inp_name、inp_username和inp_email会话值将消失。inp_password值仍然存在(但在设置会话值时,它正在被加密,md5()。
表格:
<form action="./" method="post" class="form-300">
<div class="title top">Full Name</div>
<input type="text" name="name" value="<?=$_POST['name'] ?>" />
<div class="title top">Username</div>
<input type="text" name="username" value="<?=$_POST['username'] ?>" />
<div class="title top">Email</div>
<input type="text" name="email" value="<?=$_POST['email'] ?>" />
<div class="title top">Password</div>
<input type="password" name="password" />
<input type="submit" name="submit" value="Sign Up" />
<div class="tc">By clicking Sign Up, you agree to the Terms of Use, Privacy Policy and that you are or over the age of 13.</div>
<span class="sep-text">or</span>
<a href="./?action=fb" class="btn-300 btn-fb">Sign Up using Facebook</a>
<br /><br /><br />
</form>
验证码:
<?php ob_start(); if(session_id() != 'uv241112'){
session_name("uv241112"); session_start();
$_SESSION['inp_isset'] = "eAK28";
$_SESSION['inp_name'] = $_POST['name'];
$_SESSION['inp_username'] = $_POST['username'];
$_SESSION['inp_email'] = $_POST['email'];
$_SESSION['inp_password'] = md5($_POST['password']);
}else{ session_name("uv241112"); session_start(); } ?>
<form action="./" method="post">
<?php
require_once('../resources/recaptchalib.php'); $publickey = "xxxxxxxxxx"; $privatekey = "xxxxxxxxxxxxxx";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
if ($_POST["submit_recaptcha"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
echo "You got it!";
} else {
?><div class="alert alert-error alert-440">Sorry, the text you entered was incorrect.</div><?php
# set the error code so that we can display it
$error = $resp->error;
}
}
echo recaptcha_get_html($publickey, $error);
?>
<br/>
<input type="submit" name="submit_recaptcha" value="Check" class="btn-300 btn-green" />
</form>
<?php echo $_SESSION['inp_name']; ?>
<?php echo $_SESSION['inp_username']; ?>
<?php echo $_SESSION['inp_email']; ?>
<?php echo $_SESSION['inp_password']; ?>
<?php ob_flush(); ?>