Filled form is passing empty string on server (but works OK on localhost)

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.

Any ideas? (This has flummoxed me for a day and a half! :D) I have double-checked that files on the web server are latest versions and are in the correct directories.

The form HTML:

[code]

  



[/code]

test.php:
[php]

<?php session_start(); if (md5($_POST['human']) == $_SESSION['randomnum']) { echo '; } else { echo '; } ?>

[/php]

there is a quote missing off the end of both your echo’s

</script>;

Should be

</script>';

try putting at the top
[php]echo $_POST[‘human’];[/php]

Or try

[php] if( isset($_POST[‘human’])){
echo ‘human is set’;
}else{
echo ‘human not set’;
}[/php]

Thanks for your reply

Oops! For (intended) simplicity for posting here, I removed a option before posting here and inadvertently deleted the terminating quotes; sorry.

</script>;

Should be

</script>';
try putting at the top [php]echo $_POST['human'];[/php]

I have used:
[php]echo $_POST[‘human’];
echo “
”;
echo md5($_POST[‘human’]);
echo “

”;
echo $_SESSION[‘randomnr’];
echo “
”;
echo $_SESSION[‘randomnum’];[/php]

randomnr is the number generated for the image:
[php]$randomnr = rand(10000, 99999);
$_SESSION[‘randomnum’] = md5($randomnr);[/php]

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.

(Apologies for mangling the quoting above: there doesn’t seem to be a modify/edit option to allow me to correct it)

try adding value to the text input

<input type="text" size="20" name="human" value="" />

Thanks for the suggestion, but it has made no difference. Even if I give a default value, e.g.:

<input type="text" size="20" name="human" value="enter numbers here" />

the default is passed to the test.php file on localhost, but on my webserver it still passes a blank string.

Something is stopping the post being sent to the php
Do you use die() or exit() in your script ?

Have you tried adding another input and echoing it out seems strange to not be posting the form value?

Bingo! Cracked it at last: initialised $-SESSION variables in test.php

[php]<?php
session_start();
$_SESSION[‘ishuman’]= md5($_POST[‘human’]);
$_SESSION[‘randomnum’]= md5($_SESSION[‘randomnr’]);

if ($_SESSION['ishuman'] == $_SESSION['randomnum'])	{ echo 

(etc)
[/php]

Not sure why I need to do that on the web server, but not on localhost, but hey…

Much appreciation for your efforts, Noodles!

Now, how do I mark this as [SOLVED]…?

I was not sure what you had in your session, did dumping the session vars help ?

I marked it as solved.

Didn’t get around to trying the dump: your post came through as I was testing what turned out to be the solution.

I marked it as solved.
So did I! :D

Thanks again for your time & help.

Sponsor our Newsletter | Privacy Policy | Terms of Service