Sending an Alert() in javascript from an echo() in PHP is not good practice and does not allow any additional configuration, such as adding the effects you want.
The only advantage of the method you used is that the redirect will only occur after Alert() is closed, since it has a modal behavior and therefore leaves the browser idle until it is answered.
A solution that would allow a little more customization would be to use, for example, jquery UI. As in the example:
<?php
session_start();
$credito = $_GET['credito'];
$soma = @$_SESSION['valor_total'] += $_GET['valor'];
if($soma <= $credito){
header('Location: ../../painel.php');
} else {
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Aviso</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
$(function() {
$( "#dialog" ).dialog({
dialogClass: "no-close",
autoOpen: false,
show: 'fade',
hide: 'fade',
modal: true,
buttons: [
{
text: "Retornar",
click: function() {
location.href='../../painel.php';
}
}
]
});
});
</script>
</head>
<body>
<div id="dialog" title="Ocorreu um problema!">
<p>Desculpe, ultrapassou seu limite de crédito!</p>
</div>
</body>
</html>
<?php } ?>
Wouldn’t it be better not to have javascript? Look at https://github.com/h5bp/html5-boilerplate/blob/master/404.html -> Minimum CSS without javascript. Want a return button?
<a href=
...– Gustavo Rodrigues