Jump to content

Compare javascript variable to PHP variable? Not working.


Recommended Posts

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;
}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.