PHP用户警告用break例程更改$_SESSION变量


PHP user alert to change $_SESSION variable with break routine

我有一个脚本,它需要用户交互来重写带有yes/no选项的SESSION变量。

yes的响应会导致一个简单的头重定向(我已经可以做到这一点了)。

    echo ("<SCRIPT LANGUAGE='JavaScript'>
            window.alert('You already are subscribed to a plan, would you like to change your plan at this time?')
            window.location.href='../index.php?p=payment';
    </SCRIPT>");

但是no的响应应该会中断子程序并"完成"PHP脚本的其余部分。

如何向用户提供"是/否"选项来更改会话变量,其中"否"将导致PHP脚本的延续?

为此目的使用alert是不合适的

更好地使用javascript的confirm框,它显示一个带有yesno选项的确认框,并且没有选项阻止事件发生

<script>
     if(confirm('You already are subscribed to a plan, would you like to change your plan at this time?'))
     { 
           window.location.href='../index.php?p=payment';
     }
</script>

只有当用户点击

时,这才会起作用