Convert JS function

Asked

Viewed 26 times

0

I have the following html/js script below that adds an IP via API using the URL, however in this URL you pass my User and password of the site, just as it is via javascript, anyone who is in VIEW PAGE CODE, will be able to see my user and password, could convert this to PHP so that people who access it can’t see this information?

If anyone can help, I’d be grateful, I don’t have much sense of back-end programming.

/*--------- CONTEUDO HTML ---------*/
<div id="minhaAPI">
    <p>Adicionar IP: <input type="text" id="ipAdd"></p>
    <p><input type="submit" onclick="ipChange()" value="Enviar"></p>
</div>

/*--------- CONTEUDO JS ---------*/
<script>
    function ipChange(){
    let urlApi = 'https://SITE.COM.BR/dashboard/api/ips/add/MeuUsuarioAPI/MINHASENHA/';
    let elementoIp = document.querySelector('#ipAdd');
    let urlAdd = urlApi + elementoIp.value;

    fetch(urlAdd).then(function(response) {
      if(response.ok) {
        alert('IP adicionado!');
      } else {
        alert('Houve um erro ao conectar ao servidor!');
      }
    })
    .catch(function(error) {
      alert('Houve um erro na requisição: ' + error.message);
    });
    }
</script>
No answers

Browser other questions tagged

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