brady123 Posted October 26, 2011 Share Posted October 26, 2011 This is both javascript and PHP, so I'll try here. I'm trying to validate a form using a generated key but I can't get the form to validate. I'm even looking in the source code of the generated page, taking the key that is generated, but the form is still not validated. If I substitute the PHP part for an arbitrary word the form will validate, but it won't validate against the PHP variable. Here is my code. Anyone know why this wouldn't work? Thanks for your help! if (document.forms["frm"]["captcha"].value != "<?php echo $_SESSION['key']; ?>") { document.getElementById('response').innerHTML = "Text did not match image."; frm.captcha.focus() return false; } Quote Link to comment https://forums.phpfreaks.com/topic/249819-compare-javascript-variable-to-php-variable-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2011 Share Posted October 26, 2011 You wouldn't want to perform the check in javascript anyway because anyone can learn the key to enter by simply looking at the source of the page in their browser. Quote Link to comment https://forums.phpfreaks.com/topic/249819-compare-javascript-variable-to-php-variable-not-working/#findComment-1282284 Share on other sites More sharing options...
brady123 Posted October 26, 2011 Author Share Posted October 26, 2011 I'm not too concerned with that, more with bots spamming me. Will bots be smart enough to read this? Quote Link to comment https://forums.phpfreaks.com/topic/249819-compare-javascript-variable-to-php-variable-not-working/#findComment-1282289 Share on other sites More sharing options...
PFMaBiSmAd Posted October 26, 2011 Share Posted October 26, 2011 If the benefit is great enough, the hacker behind the bot script will enter the regular expression necessary to scrape that value out of the page so that the bot script can automatically submit to your site. Quote Link to comment https://forums.phpfreaks.com/topic/249819-compare-javascript-variable-to-php-variable-not-working/#findComment-1282290 Share on other sites More sharing options...
brady123 Posted October 26, 2011 Author Share Posted October 26, 2011 Assuming I'm fine with it showing, do you know why it's it working? Quote Link to comment https://forums.phpfreaks.com/topic/249819-compare-javascript-variable-to-php-variable-not-working/#findComment-1282305 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.