Javascript alert and php header

后端 未结 7 927
执念已碎
执念已碎 2020-12-18 10:33

I got a little problem. When I got my PHP script without header it\'s fine, I am getting javascript alert box. But when I use header before alert it\'s not working. It\'s re

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 11:10

    Your error is in the structure of your code. PHP, even in OOP is procedural and will run each line one after the other. So the way you've structured your code means the page is redirected before your echo. A better method is to use the javascript alert box to redirect your page using:

    var prompt=window.confirm("message here. \r\n"+"Do you want to redirect?");
    if(prompt)document.location.href='http://dunno.com/file.php');
    

提交回复
热议问题