it is possible to create Javascript by php, but it will not necessarily be created by php, because php is not executed on the client machine, but on the server generating the HTML (js and css) code for the client
<?php
echo "<script>alert('bem vindo ao site');</script>";
?>
it is not very recommended to pass a message through Alert, that is the user himself can disable Alert, so it may happen that he does not receive your message the second time, a way to circumvent it would be a hidden part in the page with the message, example a div
<div id="kodomsg" style="display: none">
senha invalida
</div>
when you need to display that message simply display it, you can use JS to do it dynamically
<script>
var minhamsg = document.getElementById("kodomsg");
minhamsg.style.display = "block"; //"none" para ocultar
</script>
Voce can create a function to display/hide and call it for a specific event, such as pressing a button
<div id="kodomsg" style="display: none">
era uma vez um botão ... fim da historia
</div>
<input type="button" value="aperte" onclick="kodofun()">
<script>
function kodofun(){
var minhamsg = document.getElementById("kodomsg");
minhamsg.style.display = "block"; //"none" para ocultar
}
</script>
not necessarily need to be statico Voce can change the own message dynamically by JS too
<div id="kodomsg" style="display: none">
senha invalida
</div>
<script>
var minhamsg = document.getElementById("kodomsg");
minhamsg.innerHTML = "essa é a nova msg";
</script>
Voce can even create something similar to Alert, let the floating div by overwriting the page with a button to close it using js and css, even can customize it however you want
<style>
#kodomsg{
background-color: blue;
width: 200px;
height: 60px;
position: absolute;
left: 20%;
top: 20%;
}
</style>
<div id="kodomsg">
bem vindo ao site<br>
<input type="button" value="fechar" onclick="kodofechar()">
</div>
<script>
function kodofechar(){
var minhamsg = document.getElementById("kodomsg");
minhamsg.style.display = "none";
}
</script>
has many interesting ways of doing this as well as there are many applications for it (ps: this example I get ugly for a lot kkk)
A modal that resembles an Alert, because Alert is kind of "bland" and besides being defined by the browser its design. Modal type example: http://plnkr.co/edit/NePR0BQf3VmKtuMmhVR7?p=preview
– Don't Panic
Look, there are N tools to generate "most beautiful" Leds, such as Sweetalert. The problem with Alert, in my opinion, is that it is ugly to the end user.
– Diego
Whenever someone says that the simplest solution of all, native to the language and universally implemented in all browsers is not a good solution, suggest them to look for a psychologist. She probably suffers from Not-Invented-Here Syndrome.
– Oralista de Sistemas