Protect ajax code without Session

Asked

Viewed 18 times

0

Hi. I’m having a hard time figuring out how to protect an ajax code on my page. I have a PHP registration with a form and have a field create a username. But when the user leaves the field I check through an ajax code if the user already exists. But the ajax code is exposed in the browser console to the page that does the checking. It has how to hide this ajax or circumvent it somehow?

$("#usuario").blur(function(e){
    e.preventDefault();
    var name=$(this).val();
    $.ajax({
      type: 'POST',
      url: 'verifica_usuario.php',
      data: {
       nome:name,
      },
      success: function (response) {
          if($("#usuario").val()==""){
              $('#name_status').html("");
              $("#usuario").css("background-color","#ffffff");
              $("#enviar").attr("disabled",false);
          }else if(response=="true"){
              $('#name_status').html("Já existe esse usuário cadastrado");
              $("#usuario").css("background-color","#F6CECE");
              $("#enviar").attr("disabled",true);
          }else if(response=="false"){
              $( '#name_status' ).html("Usuário válido");
              $("#usuario").css("background-color","#CEF6D8");
              $("#enviar").attr("disabled",false);
          }
      }
  });
});
  • How so hide?

  • Hide so that the user enters the browser console and does not see this source code above as it is linked to my page

  • You can’t hide it, you could minify the code, but I guess.

  • front-end vc not hidden vc should protect your system at the level of backend.

  • and how I would do that?

  • I can’t hide the Ajax request, but I did a check in the php code that searches the user. If someone tries to access the file directly through the url I redirect it. For now I think it will serve.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.