jaqkar Posted February 21, 2007 Share Posted February 21, 2007 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 More sharing options...
skali Posted February 21, 2007 Share Posted February 21, 2007 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); } Link to comment https://forums.phpfreaks.com/topic/39461-image-verification-help/#findComment-190492 Share on other sites More sharing options...
jaqkar Posted February 22, 2007 Author Share Posted February 22, 2007 Can you show me with my code how to use with get please? Link to comment https://forums.phpfreaks.com/topic/39461-image-verification-help/#findComment-191081 Share on other sites More sharing options...
skali Posted February 22, 2007 Share Posted February 22, 2007 <?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> Link to comment https://forums.phpfreaks.com/topic/39461-image-verification-help/#findComment-191159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.