Jump to content

Datatable - Requested Unknown Parameter after User Inactivity


Recommended Posts

I am developing a simple role based PHP application in which Data Table is implemented. The scenario goes as The user will be signing in to the system using session and cookies. his role would be identified with the same session and cookies which matches user credentials and fetch table records as per the role. The problem I am facing is after sometime of inactivity whenever a POST request is made, I am having an error - datatables warning table id= - requested unknown parameter '0' for row 0 column 0 tn/4

Its working fine in local. I thought increasing sessions timeout might help, but unfortunately NO. its getting logged out after 30 mins although every session is set manually in codes, php.ini and CPanel's PHP Selector. I will share the code block below.

logging in

 

if(mysqli_num_rows($Query)==1)
{
    if(!empty($_POST["rememberme"]))
    {
        setcookie ("username", $_POST["username"], (time() + 31536000));
        setcookie ("password", $_POST["password"], (time() + 31536000));
    }
    else
    {
        if(isset($_COOKIE["username"]))
        {
            setcookie ("username", "");
        }
        if(isset($_COOKIE["password"]))
        {
            setcookie ("password", "");
        }
    }
    if (!session_id()) session_start();
    $_SESSION['adminsuccess'] = $username;
    $_SESSION['user'] = $username;
    
    //Session Management
    $_SESSION['expire'] = time();

    header('Location: admin_interface.php');
    die();
}

Then as soon as he logs in he will be redirected to admin_interface.php. the session management is handled as this there.

 

<?php
ini_set('session.gc_maxlifetime', 31536000);
//Session Management
if (!isset($_SESSION['adminsuccess']))
{
    header("Location:login.php");
}
else
{
    if((time()-$_SESSION['expire']) > 31536000)
    {
        session_destroy();
    }
    else{
        echo "admin user logged in";
    } 
}
?>


Then in the same class I am implementing Server Side DataTable as well which fetches the data from JSON through another class as below.

 

var table = $('#example').DataTable( {
    "processing":   true,
    "serverSide":   true,
    "order": [[ 1, "asc" ]],
    "paging"    :   true,
    "searching" :   true,
    "sDom": 'Brtip',
    "defaultContent": "-",
    "targets": "_all",
    "iDisplayLength"    :   100,
    "ajax": {
        url  :"fetchdatarecord.php",
        type : "POST",
    },
    "autoWidth": false,
    "aoColumnDefs": [{ "bSortable": false, "bSearchable": false, "aTargets": [1,2,3,4 ]},],
    "aoColumns": [{ "sWidth": "5%" }, { "sWidth": "5%" },{ "sWidth": "2%" }, { "sWidth": "3%" },{ "sWidth": "2%" }]
} );

Finally on fetchdatarecord I am getting the data as this with columns and set with JSON

 

if($role == "admin"){
    $subdata[]=$row[0];
    $subdata[]=$row[1];
    $subdata[]=$row[2];
    $subdata[]=$row[3];
    $subdata[]=$row[4];
}

Then Finally -

 

$json_data=array(
    "draw"              =>  intval($request['draw']),
    "recordsTotal"      =>  intval($totalData),
    "recordsFiltered"   =>  intval($totalFilter),
    "data"              =>  $data
);
echo json_encode($json_data);

All fetching records are working fine. except, as mention due to the user inactivity, the error throws up and the tables are going empty. if I reload the page it takes me to login.php.

First things first: confirm whether the session timeout is the problem. Because it sounds like you're not entirely sure that's the case.

Should be easy enough to confirm: wait 30 minutes, then try browsing the site and see if you've been logged out. Or more precisely, and especially if you have some Remember Me-type functionality, see if the session ID changes.

Then this isn't a datatables problem. It's a session problem.

 

16 hours ago, roshan_zaid said:

I thought increasing sessions timeout might help, but unfortunately NO. its getting logged out after 30 mins although every session is set manually in codes, php.ini and CPanel's PHP Selector.

Increasing the session duration is the answer, but there are multiple settings to consider.

What does phpinfo() say your session.* values are?

On 3/31/2021 at 2:00 AM, roshan_zaid said:

I have set the session maxlifetime to 31536000 which is an year. why the session is being destroyed or timingout.

What about the other settings?

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.