-2

ホームページにログインフォームがあります。ログインしたユーザー名に基づいて別のものに変更できますか?

例えば

<form id="form1" name="form1" method="post" action="testconnect.php">
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username" />
  </p>
  <p>
    <label for="password">Password:</label>
    <input type="text" name="password" id="password" />
  </p>
  <p>
    <input type="submit" name="login" id="login" value="Submit" />
  </p>
</form>

これをホームページで変更して表示できますか

おかえりなさい「ユーザー名」。ログアウト

4

2 に答える 2

1

それで、私が正しく理解しているなら、ユーザーがすでにログインしている場合はフォームを非表示にし、代わりにメッセージにユーザー名を表示したいですか?はい、できます。PHPセッションを使用してユーザーデータを保存している場合は、次のようにすることができます。

<?php
// Make sure to start a session first
if(!session_id()) {
    session_start();
}

// If a username is set, display a welcome message.
if(isset($_SESSION['username'])) {
    echo "Welcome back " . $_SESSION['username'];
} else {
    // No login session found, output the form here instead
?>
<form id="form1" name="form1" method="post" action="testconnect.php">
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username" />
  </p>
  <p>
    <label for="password">Password:</label>
    <input type="text" name="password" id="password" />
  </p>
  <p>
    <input type="submit" name="login" id="login" value="Submit" />
  </p>
</form>
<?php
}
于 2012-12-06T10:52:24.997 に答える
0

ログインデータを入力し$_COOKIE、cookie echo'Hello username'を見つけた場合は、フォームをechoします

于 2012-12-06T10:49:48.427 に答える