Tetenterre Posted August 21, 2012 Share Posted August 21, 2012 I am trying to implement a simple CAPTCHA on my web site. It works as I intend on localhost (Apache server on my laptop), but $_POST['human'] appears to reach test.php as an empty string (MD5=d41d8cd98f00b204e9800998ecf8427e) when I upload the same files to my web server. The CAPTCHA image is of a random number; the number is stored as an MD5 string for comparison as $_SESSION['randomnum']. This bit seems to work properly, and test.php picks up this number (and, hence, MD5 string) correctly. The form HTML: <form action="test.php" method="post"> <img src="captcha02.php" align="absmiddle" /> <input type="text" size="20" name="human" /> <input type="submit" name="done" value="I'm human!" /> <br /><br /> </form> test.php: <?php session_start(); if (md5($_POST['human']) == $_SESSION['randomnum']) { echo '<script language="javascript"><!-- location.replace("astunit_course_booking_form.php") //--> </script>'; } else { echo '<script language="javascript"><!-- location.replace("astunit_course_human_test.php") //--> </script>'; } ?> I have used this to try to see what is happening: echo $_POST['human']; echo "<br />"; echo md5($_POST['human']); echo "<br /><br />"; echo $_SESSION['randomnr']; echo "<br />"; echo $_SESSION['randomnum']; randomnr is the number generated for the image: $randomnr = rand(10000, 99999); $_SESSION['randomnum'] = md5($randomnr); Confirms that the form passes human correctly when testing on localhost my laptop, but not when it is uploaded to the web server, where it passes an empty string. Sample output on localhost: 54052 67e3aa6a8dce9aaf1ec9563bbac40582 54052 67e3aa6a8dce9aaf1ec9563bbac40582 Sample output on web server: d41d8cd98f00b204e9800998ecf8427e 46850 1cb9a2cdf84ff27e0ff8aa17644b15e3 Any ideas? (This has flummoxed me for a day and a half! ) I have double-checked that files on the web server are latest versions and are in the correct directories. Quote Link to comment https://forums.phpfreaks.com/topic/267360-filled-form-is-passing-empty-string-on-server-but-works-ok-on-localhost/ Share on other sites More sharing options...
Tetenterre Posted August 21, 2012 Author Share Posted August 21, 2012 Bingo! Cracked it at last: initialised $-SESSION variables in test.php <?php session_start(); $_SESSION['ishuman']= md5($_POST['human']); $_SESSION['randomnum']= md5($_SESSION['randomnr']); if ($_SESSION['ishuman'] == $_SESSION['randomnum']) { echo (etc) Not sure why I need to do that on the web server, but not on localhost, but hey... Now, how do I mark this as [sOLVED]..? Quote Link to comment https://forums.phpfreaks.com/topic/267360-filled-form-is-passing-empty-string-on-server-but-works-ok-on-localhost/#findComment-1371061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.