Can't call javascript alert alertify library from PHP



PHP Snippet 1:

if(empty($user_password)){ 
     echo "<script>$(function(){alertify.alert('Por favor, ingrese su usuario y contraseƱa');})</script>";
  }

PHP Snippet 2:

<?php

//partial php code

if($saveData)
{
$_SESSION['variable'] = 'text here';
header('location:link.php');
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
    <link href="path/alertify.css"></link>
</head>
<body>
<?php if(isset($_SESSION["variable"])):?>
    
    <script>
        window.onload = () => {
            alertify.alert("Title", "<?=$_SESSION["variable"]?>");
        }
    </script>
    
    <?php unset($_SESSION["variable"]); endif;?>
    
    <script src="path/alertify.js"></script>
</body>