skip to Main Content

I want to run a script on a PHP file, but it is not running. It runs the header before the function runs so don’t know how to run first the script

iniciales();
header('Location: Lista_libros.php');//This runs before the funtion

function iniciales(){
echo '<script type="text/javascript">
    alert("test");
</script>';
}

2

Answers


  1. it will actually run, but you can’t see it because of redirection,
    well, if the server sends a redirection header, the browser redirects and therefore "changes the URL", so your alert and other kinds of stuff will be wiped out from the screen

    Login or Signup to reply.
  2. PHP is a server side script language.
    JavaScript is client side script language.

    So in your case if you want to run JavaScript code try redirecting from your JavaScript and remove header function form PHP code .
    If you do this so your JavaScript code can execute .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search