Jump to content

Image verification help


jaqkar

Recommended Posts

Please tell me why i cannot get this to display: Image validation MATCHED

The images is displaying properly from <img src="formvalid_img.php" alt="validation picture" />

 

 

<?php
// image verification 

session_start();
$_SESSION['val_text']=substr(sha1(rand()),0,5);


$valid =  $_POST['valid'];

if($_SESSION['val_text']!=$_POST['valid'] || !isset($_POST['valid']) || $_POST['valid']=="")
{
echo "Image validation did not match";
}
else
{
echo "Image validation MATCHED";
}	 

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

  <form name="frm" id="frm" method="post"  action="test.php" >
      <table width="100%" border="0" cellpadding="3" cellspacing="0" class="b1">
        <tr bgcolor="#F2F5F7">
          <td class="b1"><a name="comment" id="comment"></a></td>
        </tr>
        <tr>
          <td > </td>
        </tr>
        <tr>
          <td >
              <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                <tr bgcolor="#FFFFFF">
                  <td width="28%" class="NewsSubhealine"> </td>
                  <td width="72%"><p><img src="formvalid_img.php" alt="validation picture" /></p>
                    <p><input name="valid" type="text" id="valid" /></p></td>
                </tr>
                <tr bgcolor="#FFFFFF">
                  <td class="NewsSubhealine"> </td>
                  <td><input name="Submit" type="submit"  value="Submit" /></td>
                </tr>
            </table></td>
        </tr>
      </table>
    </form>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/39461-image-verification-help/
Share on other sites

You are settting session variable on every page refresh:

 

$_SESSION['val_text']=substr(sha1(rand()),0,5);

 

So after the user has posted image text the session value will again reset with new random value.

 

you can use:

if($_SERVER['REQUEST_METHOD']=='GET'){
    $_SESSION['val_text']=substr(sha1(rand()),0,5);
}

<?php
session_start();

if(empty($_POST['valid']))
   $_SESSION['val_text']=substr(sha1(rand()),0,5);


$valid =  $_POST['valid'];

if($_SESSION['val_text']!=$_POST['valid'] || !isset($_POST['valid']) || $_POST['valid']=="")
{
echo "Image validation did not match";
}
else
{
echo "Image validation MATCHED";
}	 

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

  <form name="frm" id="frm" method="post"  action="test.php" >
      <table width="100%" border="0" cellpadding="3" cellspacing="0" class="b1">
        <tr bgcolor="#F2F5F7">
          <td class="b1"><a name="comment" id="comment"></a></td>
        </tr>
        <tr>
          <td > </td>
        </tr>
        <tr>
          <td >
              <table width="100%"  border="0" cellspacing="0" cellpadding="5">
                <tr bgcolor="#FFFFFF">
                  <td width="28%" class="NewsSubhealine"> </td>
                  <td width="72%"><p><img src="formvalid_img.php" alt="validation picture" /></p>
                    <p><input name="valid" type="text" id="valid" /></p></td>
                </tr>
                <tr bgcolor="#FFFFFF">
                  <td class="NewsSubhealine"> </td>
                  <td><input name="Submit" type="submit"  value="Submit" /></td>
                </tr>
            </table></td>
        </tr>
      </table>
    </form>

</body>
</html>

Archived

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

×
×
  • Create New...

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.