The problem:
Hi, I have a 'form' that is submitted via AJAX, and during the submission / validation process it makes a call to another page to check that the captcha is the same as the variable stored in the [tt]$_SESSION[/tt]. If it is, then it returns a string and the sending process continues, as you would expect.
This works perfectly well in Firefox 3.6, IE7 (don't have access to 6 or 8 at the moment) and Safari 4. However, in Opera 10 and Google Chrome 4 it always fails the comparison. So upon failure, I had the php comparison script echo the session value, then have the ajax script alert the [tt]responseText[/tt]and it is completely different to the value on the page. But this alerts the correct value in FF, IE and Safari.
I have googled this problem and not found anything conclusive or useful.
It's been puzzling me for a day now. It all seems logically correct. Can anyone offer any insight into this and why it is not working on Opera 10 and Chrome 4?
Here's the captcha generation:
and now the ajax request:
and here is the comparison:
Thanks for any help, you may just be preventing premature baldness!
Dan
________________________________
Top 10 reasons to procrastinate:
1)
Hi, I have a 'form' that is submitted via AJAX, and during the submission / validation process it makes a call to another page to check that the captcha is the same as the variable stored in the [tt]$_SESSION[/tt]. If it is, then it returns a string and the sending process continues, as you would expect.
This works perfectly well in Firefox 3.6, IE7 (don't have access to 6 or 8 at the moment) and Safari 4. However, in Opera 10 and Google Chrome 4 it always fails the comparison. So upon failure, I had the php comparison script echo the session value, then have the ajax script alert the [tt]responseText[/tt]and it is completely different to the value on the page. But this alerts the correct value in FF, IE and Safari.
I have googled this problem and not found anything conclusive or useful.
It's been puzzling me for a day now. It all seems logically correct. Can anyone offer any insight into this and why it is not working on Opera 10 and Chrome 4?
Here's the captcha generation:
Code:
session_start();
[green]//i added this to ensure we were getting the same session var each time[/green]
unset($_SESSION['k']);
[green]//set up captcha:[/green]
$random_str = md5(microtime());
$result_str = substr($random_str,6,6); [green]//this var goes into img later on[/green]
[green]//set session var 'k'[/green]
$_SESSION['k'] = $random_str;
...snip - generating img below...
and now the ajax request:
Code:
...snip...
var url = "/inc/vcap.php";
url = url + '?c=' + document.getElementById('incap').value;
url = url + '&sid=' + Math.random();
check_cap.open("GET", url, true);
check_cap.send(null);
and here is the comparison:
Code:
if (isset($_GET['c'])){
$captcha = $_GET['c'];
session_start();
$key = substr($_SESSION['k'],6,6);
if($captcha == $key){
echo('1');
}
else{
echo('0');
}
}
Thanks for any help, you may just be preventing premature baldness!
Dan
________________________________
Top 10 reasons to procrastinate:
1)