How to send data in JQuery ajax safely?

1

I send data through jquery $.ajax to the server and now that I have to send the id of the user I thought that this is not very safe ... since anyone who goes to source code or to inspect the code can see perfectly the variables, their values (they will see the user id), where I am sending and with what new variables are being sent.

$(document).on("click", '.boton', function () {
    var user = <?php echo $user_actual; ?>; // se ve así: var user = 2;
    var datos = <?php echo $get_datos; ?>; // se ve así: var datos = 11;
    $.ajax({
        url:'../backend.php',
        type:'GET',
        data:{user_ident:user, datos_ident:datos},
        success:function (data) {
        }
    });
});

What should I do? The only thing that occurs to me is to hide the JQuery with PHP echos.

    
asked by Menzezzz 29.08.2018 в 15:55
source

1 answer

0

For sensitive data and not only sensitive, if not the ones that you do not want the user to be able to modify in any of your ajax requests, you should make use of the variable superglobal $_SESSION . Thus avoiding having to send this information in each request.

    
answered by 30.08.2018 в 08:06