简单的验证码会话问题
我在验证码图像和会话变量方面遇到了一个非常荒谬的问题。
http://paholo.com/npdev/tests/contact_us2 .php?add=1&confirm=new#contact
我已经多次使用过同样的“联系我们”脚本,但显然现在有些问题了。当我在脚本内运行 make_captcha.php
时,它只是不会存储 $_session['captchacode']
。
但是当我在脚本之外运行它时,它工作正常。
我在 make_captcha.php
和 contact_us2.php
脚本上都有 session_start()
。
我知道这里有一个简单的答案,但我就是看不到。
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Lotus Properties - a Los Angeles Apartment Property Management & Real Estate Company</title>
<?php include_once('includes/functions-nomysql.php'); ?>
</head>
<body>
<h2>Contact Us</h2>
<div id="contactform">
<?php
$add = $_GET['add'];
$confirm = $_GET['confirm'];
if (($add == "1") AND ($confirm == "new"))
{
echo $_POST["contact_captcha"];
echo $_SESSION["session_captchaText"];
if (($_POST["contact_captcha"] == $_SESSION["session_captchaText"]) AND ($_POST["contact_captcha"] != "" ))
{
if ($_SERVER["REQUEST_METHOD"] <> "POST")
{ // check for a true message post
die("You can only reach this page by posting from the html form");
}
}
else
{
$error = "yes";
$message .= ('<span class="red">Please Enter the Confirmation Code</span><br />');
}
if ($error == "yes")
{
?>
<p>Please Make Corrections to the Contact Us Form</p>
<p><?php echo $message; ?></p>
<form action="contact_us2.php?add=1&confirm=new#contact" method="POST">
<p>Please Confirm this Code <br /><img src="http://www.paholo.com/npdev/tests/includes/make_captcha.php" /> <br /><input type="text" name="contact_captcha" value="enter code" size="10" width="220" height="50" /></p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
<?php
}
else
{
$mailuser = "$contact_email";
$header = "Return-Path: [email protected]\r\n";
$header .= "From: Lotus Properties Contact Us <[email protected]>\r\n";
$header .= "Content-Type: text/html;";
$mail_body = ('Thank you for sending in your Contact Us request to <a href="http://www.lotusproperties.com">Lotus Properties</a>. We will respond to your message as soon as possible. Thank you.');
if (mail ($mailuser, 'Contact Us', $mail_body, $header))
{
echo ('<p>Your Message has been Sent</p>');
}
else
{
echo ('<p>Problem sending message. <a href="contact_us.php">Try again</a></p>');
}
}
}
else
{
?>
<form action="contact_us2.php?add=1&confirm=new#contact" method="post" >
<p>Please Confirm this Code <br /><img src="http://www.paholo.com/npdev/tests/includes/make_captcha.php" /> <br /><input type="text" name="contact_captcha" value="enter code" size="10" width="220" height="50" /></p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
<?php
}
?>
</div><!-- end of contact form -->
</body>
</html>
I've got a quite ridiculous problem with a captcha image and session variable.
http://paholo.com/npdev/tests/contact_us2.php?add=1&confirm=new#contact
I've used this same "Contact us" script numerous other times but clearly something is now off with it. It just won't store the $_session['captchacode']
when I run the make_captcha.php
inside the script.
But when I run it outside the script it works fine.
I have session_start()
on both themake_captcha.php
and the contact_us2.php
script.
I know there is a simple answer here but I just can't see it.
<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Lotus Properties - a Los Angeles Apartment Property Management & Real Estate Company</title>
<?php include_once('includes/functions-nomysql.php'); ?>
</head>
<body>
<h2>Contact Us</h2>
<div id="contactform">
<?php
$add = $_GET['add'];
$confirm = $_GET['confirm'];
if (($add == "1") AND ($confirm == "new"))
{
echo $_POST["contact_captcha"];
echo $_SESSION["session_captchaText"];
if (($_POST["contact_captcha"] == $_SESSION["session_captchaText"]) AND ($_POST["contact_captcha"] != "" ))
{
if ($_SERVER["REQUEST_METHOD"] <> "POST")
{ // check for a true message post
die("You can only reach this page by posting from the html form");
}
}
else
{
$error = "yes";
$message .= ('<span class="red">Please Enter the Confirmation Code</span><br />');
}
if ($error == "yes")
{
?>
<p>Please Make Corrections to the Contact Us Form</p>
<p><?php echo $message; ?></p>
<form action="contact_us2.php?add=1&confirm=new#contact" method="POST">
<p>Please Confirm this Code <br /><img src="http://www.paholo.com/npdev/tests/includes/make_captcha.php" /> <br /><input type="text" name="contact_captcha" value="enter code" size="10" width="220" height="50" /></p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
<?php
}
else
{
$mailuser = "$contact_email";
$header = "Return-Path: [email protected]\r\n";
$header .= "From: Lotus Properties Contact Us <[email protected]>\r\n";
$header .= "Content-Type: text/html;";
$mail_body = ('Thank you for sending in your Contact Us request to <a href="http://www.lotusproperties.com">Lotus Properties</a>. We will respond to your message as soon as possible. Thank you.');
if (mail ($mailuser, 'Contact Us', $mail_body, $header))
{
echo ('<p>Your Message has been Sent</p>');
}
else
{
echo ('<p>Problem sending message. <a href="contact_us.php">Try again</a></p>');
}
}
}
else
{
?>
<form action="contact_us2.php?add=1&confirm=new#contact" method="post" >
<p>Please Confirm this Code <br /><img src="http://www.paholo.com/npdev/tests/includes/make_captcha.php" /> <br /><input type="text" name="contact_captcha" value="enter code" size="10" width="220" height="50" /></p>
<p><input type="submit" name="submit" value="Send" /></p>
</form>
<?php
}
?>
</div><!-- end of contact form -->
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论