简体   繁体   中英

Notice: Undefined index: name in C:\wamp\www\chatsystem\index.php on line 63

I get this error... Its a chat system iver been working on for a couple of days. And the lines are:

<div id="wrapper">
    <div id="menu">
        <p class="welcome">Velkommen, <b><?php echo $_SESSION['name']; ?></b></p>
        <p class="logout"><a id="exit" href="#">Forlad Chatten</a></p>
        <script type="text/javascript">
            // jQuery Document
        $(document).ready(function(){
        //If user wants to end session
        $("#exit").click(function(){
        var exit = confirm("Are you sure you want to end the session?");
        if(exit==true){window.location = 'index.php?logout=true';}      
            });
        });
</script>

You have to start your session at the top of your file with:

session_start();

So you have access to the Session Array.

Also make sure you have set $_SESSION['name'] !

You can check if $_SESSION['name'] isset so you don't get a warning and it's only outputed when it is set like this:

<?php if (isset($_SESSION['name'])) echo $_SESSION['name']; ?>

I think you forgot to put a die() after loginFrom() on line 28 like so:

if(!isset($_SESSION['name'])){
    loginForm();
    die();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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