繁体   English   中英

php会话变量没有回显

[英]php session variable not echoing

当我运行这个脚本时,我试图通过标题将会话重定向到位置:index.php来回显会话变量($ email),但它只是回显会话值(数字1)而不是电子邮件地址,我可以弄清楚原因。 有任何想法吗? 谢谢。

<?php
session_start();
if (isset($_POST['email'], $_POST['password'])) {
    $email = $_POST['email'];
    $password = $_POST['password'];
    if ($email && $password) {
        $connect = mysql_connect("localhost", "root", "") or die("Could not connect");
        mysql_select_db("test") or die("could not find database");
        $query = mysql_query("SELECT * FROM users WHERE email='$email'&& 
            password= md5('$password')");
        $numrows = mysql_num_rows($query);
        if ($numrows != 0) {
            $_SESSION["email"] = $email;
            session_write_close();
            header("location:index.php");
            Die();
        }
        else
            echo ("not a user");
    }
    else
        echo("enter both fields");
}
?>
<html>
    <form action='edit1.php' method='POST'>
        <table align='right' bgcolor='blue'>
            <tr>
                <td>Email
                </td>
                <td>Password
                </td>
            </tr>
            <tr>
                <td><input name='email' type='text'>
                </td>
                <td><input name='password' type='password'><td>
                    <input type='submit' value='login'>
                </td>
            </tr>
        </table>
    </form>
</html>


//index.php file

<?php
session_start(); {

    echo $_SESSION['email'] or die('fail'); {

    }
}
?>

正如我在评论中所说, or die将无法奏效。 去掉它。

删除或死('失败'),它会正常工作。

函数echo返回void呈现'或die()'无用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM