-2

如何为登录用户创建菜单?

我有非注册用户的代码:

    <form name="form1" style="float: left;" method="post" action="config.php">
        <input name="myusername" type="text" id="myusername">
        <input name="mypassword" type="password" id="mypassword">
        <input type="submit" name="Submit" value="Login">
    </form>

对于已注册的登录用户,这是:

您现在登录为:YouTOPname...

4

1 回答 1

0

Use a session in PHP. Make sure to use session_start() at the top of your page otherwise sessions won't be recognised.

During the login process, create a session: $_SESSION['user'] = true

The code to decide which menu to display should look something like this:

if (isset($_SESSION['user'])) {
  //Menu for logged in member here
}
else {
  //Menu for logged out member here
}

Obviously there's other method for more dynamic web development, but this is the basic technique. Hope that helps :)

EDIT: Don't forget to unset the session when logging out, otherwise the user menu will remain visible!

于 2013-07-10T21:07:14.360 回答