Ajax request not working on apple devices

A

Anonymous

Guest
I am working on a registration system for this site: bottlesbeach.eu Basically, when a user registers or logs in, a cookie is created and inside this cookie there is a randomly generated string that will also be inserted in the mysql database in the users table. When you click on logout the cookie should delete and the random string inside the mysql db should delete, this I did as an ajax session.

Index.php onclick log-out:

Code:
    <?php 
$logged = false;
if (isset($_COOKIE["sessionid"])){
    $logged = true;

    ?> 
    <script>
    console.log("status: Logged");
    var ahr = document.getElementById('ahr');
    ahr.setAttribute('href', '');
    ahr.innerHTML="Log-out";
    ahr.onclick = function remokecookies() {
        window.location = window.location + '#notlogged';
      $.ajax({
           type: "POST",
           url: '/ajax.php',
           data:{action:'removecks'},
           cache: false,

      });
    }
  window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#logged';
        window.location.reload();
        
    }
}

    </script>
    
    <?
(Obviously I inserted a reload because otherwise the button text remained as "log-out" even if the ajax function was executed, and therefore the cookie was deleted.)

In the index I created a condition, if the cookie is there, it means that you are logged in, then at the top right there will be the log out button with the respective onclick ajax function that I showed previously. Otherwise it will be written login and clicking on it will take you to the login panel.

Ajax function (ajax.php):

Code:
<?php
if($_POST['action'] == 'removecks') {
setcookie("sessionid", "", time() - 86400 * 30);
$hostname="";
  $username="";
  $password="";
  $dbname="";
  $ckvalue = $_COOKIE["sessionid"];
$conn = new mysqli($hostname,$username, $password, $dbname); 
  if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
  ?> <script> console.log("Connection to db failed");</script><?
}
            $query = "UPDATE users SET sessionid = '' WHERE sessionid = '$ckvalue'";           
            $stmt = $conn->prepare($query);
            $stmt->bind_param("s", $sessionid);
            $stmt->execute();  
}

?>

Everything seems to work in the desktop version, but from mobile (only on apple devices), the "log-out" button remains. So, I assume that the ajax function is not executed, and the cookie is not cleared. Would anyone know how to help me?
 
Back
Top