I'm using this captcha plugin, http://code.google.com/p/cool-php-captcha/ in my website, I'm having the HTML form in my wamp server, and it is submitting it to my live sever located in http://www.example.com/experiments/emaileasy/index.php
. Now the problem is, the session return empty array and it is not retrieving when i submit the form in $.ajax, but i can able to see the value if i directly visit the url in my browser. I hardly don't know how to proceed with this,
Here is my index.php file where i'm submitting the form,
<?php
session_start();
print_r($_SESSION);die;
if(isset($_POST))
{
if (empty($_SESSION['captcha']) || trim(strtolower($_POST['captcha'])) != $_SESSION['captcha'])
{
header("HTTP/1.0 400 Bad Request");
header('Content-type: application/json');
die(json_encode(array('message' => 'Please recheck the captcha')));
}
try {
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('expo', $conn);
$status = mysql_query("INSERT INTO table SET content = '".mysql_real_escape_string($_POST['content'])."'");
header("HTTP/1.1 200 OK");
header('Content-type: application/json');
echo json_encode(array('message' => 'Success!'));
} catch (Exception $e) {
header("HTTP/1.0 400 Bad Request");
header('Content-type: application/json');
echo json_encode(array('message' => 'Failed'));
}
}
?>
Here is my JS file,
$( "#Form" ).submit(function( event ) {
// Stop form from submitting normally
event.preventDefault();
var data = "content="+$( "#content" ).val()+"&captcha="+$( "#captcha" ).val();
$.ajax({
type: "POST",
url: baseurl+'experiments/emaileasy/index.php',
data: data
});
});
If i'm submitting the form to localhost it is working properly, but when i submitting it to live server, the session returns empty array.
Here is my .htaccess file,
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers X-Requested-With
</IfModule>
Please note that, the session is set through cool-php-captcha
which lies on the server. And one more thing i noted is, when the captcha is loaded a session file is getting created and when i post the values a new session file is created in the name of PHPSESSID
passing in AJAX requests(I noted this through Firebug response headers).
I'm getting the $_POST
values also, but session return empty array when retrieve through AJAX. Please help. Thanks in advance.