-1

我的脚本需要一点帮助,我正在制作一个库登录/注销和页面,我让它工作,以便在他们登录和注销时发布表单,但如果他们正在尝试,我想把它放到哪里退出并且他们实际上从未登录它会弹出一个js警报告诉他们,我不太明白。

这是代码:

<?php
    session_start();
    include_once("connect.php");
    date_default_timezone_set("America/Winnipeg");
    $date = ("m-d-Y");
    $timeout = date("g:i:s a");

    //search for existing entries
    if ("SELECT EXISTS(SELECT * FROM signin_out WHERE
    lname='".$_POST['lastname']."' AND fname='".$_POST['firstname']."' 
    AND date='".$date."')") {

        //if they exist run this
        mysql_query("UPDATE signin_out SET timeout='" . $timeout . "' 
            WHERE lname='" . $_POST['lastname'] . "' 
            AND fname='" . $_POST['firstname'] . "' AND timeout='' ");
        header("Location: ../index.html");

        //if they don't exist run this
    } else {
        header("Location: ../index.html");
        echo "<script type='text/javascipt'>\n";
        echo "alert('You did not sign in!');\n";
        echo "</script>";
   }
?>
4

1 回答 1

0

HTTPLocation标头../index.html在 JavaScript 退出之前很久就已经将它们发送到echo了。您需要有一个logout.php带有该 JavaScript 的页面或一个$_GET用于将它们重定向到的页面的变量,并在那里触发警报框。

例如:

...
} else {
    header('Location: ../index.php?notloggedin');
}

在你的某个地方index.php

<?php
if(isset($_GET['notloggedin'])) {
    echo '<script>alert("You did not sign in!");</script>';
}
?>

虽然我发现一个alert盒子是相当侵入性的,但我宁愿这样做:

<?php
if(isset($_GET['notloggedin'])) {
    echo '<p><strong>You did not sign in!</strong></p>';
}
?>
于 2013-08-23T18:24:23.700 回答