2012-12-06 28 views
-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> 

這能在主頁上更改爲顯示

歡迎回來 「用戶名」。註銷在$_COOKIE

+1

你可以在以後嘗試嗎?在提出任何問題之前,請搜索它。 –

+0

http://www.w3schools.com/php/php_intro.asp – Manatax

回答

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 
} 
0

認沽登錄數據,如果你發現餅乾回聲「Hello用戶名」別的回聲您的形式

+0

我更喜歡會話而不是cookie。 –

+0

那麼原則是一樣的,無論1990年更喜歡什麼洗牌:) – vodich

+0

我寧願:session + webstorage – Manatax