this is js code i am calling "is_loggedin" from ajax in php folder in login.php but it always gives undefined index action
$(document).ready(function(){
$('.carousel').carousel({
pause: "false"
});
});
$("#loginId").click(function(){
$("#modalLoginId").modal("show");
});
$("#registerId").click(function(){
$("#modalRegisterId").modal("show");
});
$("#login-btn").click(function () {
var loginpasswordJSON = JSON.stringify({
"username": $('#login_username').val(),
"password": $('#login_password').val(),
});
alert(loginpasswordJSON);
console.log ("Login Started");
$.ajax({
type: 'POST',
url: 'php/login.php',
dataType: 'json', // data type of response
data: {action:"success"},
contentType:'application/json',
success: function(data){
alert("successfully logged In")
}
//error: function(jqXHR, textStatus, errorThrown){
// handleErrors('Error: ' , textStatus , errorThrown);
// }
});
console.log ("Login Ends");
return false;
}
);
login.php
<?php
$action = $_POST["action"];
if($action=="success") {
is_loggedin();
}
class USER
{
private $db;
function __construct($DB_con)
{
$this->db = $DB_con;
}
public function register($fname,$lname,$uname,$umail,$upass)
{
try
{
$new_password = password_hash($upass, PASSWORD_DEFAULT);
$stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass)
VALUES(:uname, :umail, :upass)");
$stmt->bindparam(":uname", $uname);
$stmt->bindparam(":umail", $umail);
$stmt->bindparam(":upass", $new_password);
$stmt->execute();
return $stmt;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function login($uname,$umail,$upass)
{
echo "ma";
try
{
echo "pass";
$stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
$stmt = $this->db->prepare("SELECT * FROM gy_user_detail WHERE user_name=:uname OR user_email=:umail LIMIT 1");
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
if(password_verify($upass, $userRow['user_pass']))
//$_SESSION['user_session'] = $userRow['user_id'];
{
return true;
}
else
{
return false;
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function is_loggedin()
{
echo "hahah";
// if(isset($_SESSION['user_session']))
// {
// return true;
// }
}
public function redirect($url)
{
header("Location: $url");
}
public function logout()
{
session_destroy();
unset($_SESSION['user_session']);
return true;
}
}
?>