Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在注销前发出确认警报_Javascript_Php - Fatal编程技术网

Javascript 如何在注销前发出确认警报

Javascript 如何在注销前发出确认警报,javascript,php,Javascript,Php,我想在注销我的帐户之前弹出确认警报消息。但它不会弹出,我不确定我是否把回声放在了正确的位置 <?php session_start(); session_destroy(); echo "<script> window.confirm('Are you sure to logout?');</script>"; header("location:../app/masuk.php"); //to redirect back to "index.php" after

我想在注销我的帐户之前弹出确认警报消息。但它不会弹出,我不确定我是否把回声放在了正确的位置

<?php
session_start();
session_destroy();
echo "<script> window.confirm('Are you sure to logout?');</script>";
header("location:../app/masuk.php"); 
//to redirect back to "index.php" after logging out
exit();
?>

您必须在视图而不是控制器上进行确认

假设您有一个注销按钮:

Html:

Php


您首先需要一个html链接

<a href="logout.php" onclick=" return confirm("Are You sure you want to logout?");">Logout</a>

然后在logout.php中,您应该

<?php
session_start();
session_destroy();
header('the_page_you_wish.php');

session_start();会话_destroy()?老实说,这看起来非常错误。在注销中,您创建了一个会话,并在??在youj破坏了一个会话后,你问他是否想注销?另一件事是,这不可能像你想要的那样,因为PHP是在JavaScriptUnabled之前运行的……客户端代码不会在服务器上运行。你不能像那样混合使用脚本和PHP。在加载此页面之前需要进行确认—加载此页面时,所有php进程都会在任何脚本运行之前进行,这就是为什么您看不到确认警报的原因。
<?php
// Your logout functions...
<a href="logout.php" onclick=" return confirm("Are You sure you want to logout?");">Logout</a>
<?php
session_start();
session_destroy();
header('the_page_you_wish.php');