Send parameters with query string to index.html and in index add the alert script.
<?php
unset ($_SESSION['login']);
unset ($_SESSION['senha']);
header('location:index.html?info=error&msg=1');
And in index.html
add the script:
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
if(getParameterByName('info') === 'error' && getParameterByName('msg') === '1') {
alert('Erro ao fazer Login');
}
</script>
The getParameterByName
function has been extracted from here:
link
Your code does not run because by redirecting the page with the header location in PHP the code below in javascript is not executed by the browser