-1
想創建一個用戶可以註冊一個站點然後他們可以登錄的登錄。我是要在phpmyadim中添加數據的細節,用戶登錄我希望從數據庫獲得詳細信息。我已經知道如何做到這一點,但我想知道的是,我怎麼知道當用戶登錄時會將它們帶回主頁,而右手則表示「hello emma」(或任何已登錄的用戶)用php和html創建一個登錄頁面
這裏是我的代碼
登錄
?php
\t //Start session
\t session_start(); \t
\t //Unset the variables stored in session
\t unset($_SESSION['SESS_MEMBER_ID']);
\t unset($_SESSION['SESS_FIRST_NAME']);
\t unset($_SESSION['SESS_LAST_NAME']);
?>
<form name="loginform" action="mylogin.php" method="post">
<table width="309" border="0" align="center" cellpadding="2" cellspacing="5">
<tr>
<td colspan="2">
\t \t <!--the code bellow is used to display the message of the input validation-->
\t \t <?php
\t \t \t if(isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0) {
\t \t \t echo '<ul class="err">';
\t \t \t foreach($_SESSION['ERRMSG_ARR'] as $msg) {
\t \t \t \t echo '<li>',$msg,'</li>';
\t \t \t \t }
\t \t \t echo '</ul>';
\t \t \t unset($_SESSION['ERRMSG_ARR']);
\t \t \t }
\t \t ?>
\t </td>
</tr>
<tr>
<td width="116"><div align="right">Username</div></td>
<td width="177"><input name="username" type="text" /></td>
</tr>
<tr>
<td><div align="right">Password</div></td>
<td><input name="password" type="password" /></td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><input name="" type="submit" value="login" /></td>
</tr>
</table>
</form>
檢查登錄
<?php
\t //Start session
\t session_start();
\t //Check whether the session variable SESS_MEMBER_ID is present or not
\t if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
\t \t header("location: myindex.php");
\t \t exit();
\t }
?>
我的主頁
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
\t <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Home</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
\t \t <link rel="stylesheet" href="advertising.css">
\t \t
<?php
session_start();
?>
\t \t <div id = "menu">
\t \t \t <div id='welcome'>
<?php
if(isset($_SESSION['username']))
{
echo 'Welcome ' . $_SESSION['username'];
}
?>
</div>
</div>
\t \t
\t </head>
\t <body>
\t
\t <header>
\t \t
\t \t <nav>
\t \t \t <ul>
\t \t \t \t <li><a href="index.html"><img src="../img/buzz_party.png" class="imglogo"></a></li>
<li><a href="index.html">Home</a></li>
\t \t \t \t <li><a href="aboutus.html">About us</a></li>
\t \t \t \t <li><a href="contact.html">Contact</a></li>
<li><a href="advertising.html">Supplies</a></li>
<li><a href ="logintest.php">Login</a></li>
<li><a href="register.php">Register</a></li>
\t \t \t </ul>
\t \t </nav>
\t </header>
\t
\t
\t \t
\t \t <div id="slideshow">
\t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nisl est, fringilla eget sem in, viverra ornare enim. Fusce ac finibus leo. Nullam quis mauris nunc. Sed in
\t \t \t ipsum consectetur, faucibus justo quis, suscipit tortor. Vestibulum sed augue egestas justo dictum sagittis. Nam eu enim blandit lacus accumsan hendrerit eu eget lorem. Nullam
\t \t \t sed augue dictum sapien mattis accumsan. Mauris arcu ligula, mattis in blandit vitae, vehicula quis mi. Integer tempor felis ac vulputate semper. Proin sed mauris at orci facilisis
\t \t \t luctus id vel nibh. Proin egestas suscipit nulla, ac ornare erat imperdiet a. Integer convallis volutpat pretium. Mauris ac.</p>
\t \t </div>
\t \t
\t \t <div id="container">
\t \t \t <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam placerat pulvinar urna, ac dapibus lectus iaculis et. Suspendisse eu velit commodo,
\t \t \t aliquet eros vitae, vehicula nibh. Integer ante est, scelerisque id fermentum sed, sagittis dignissim neque. Proin id felis ante. Praesent sed massa in tellus consectetur maximus.
\t \t \t Quisque auctor sem ac felis sagittis, non imperdiet tortor tincidunt. Quisque at lorem vitae mi posuere aliquet. In hac habitasse platea dictumst. Praesent ultrices, enim non blandit
\t \t \t ullamcorper, odio orci vulputate mauris, in congue nulla elit a turpis.</p>
\t \t \t <p>Aenean tempus risus ac enim cursus, id varius dolor aliquam. Donec mauris tortor, efficitur ut condimentum sit amet, pellentesque in nisl. Duis mattis nisi non congue ullamcorper.
\t \t \t In rhoncus lobortis vulputate. Pellentesque lacinia finibus libero, elementum volutpat lectus faucibus vitae. Quisque interdum ipsum et rutrum aliquet. Lorem ipsum dolor sit amet, consectetur
\t \t \t adipiscing elit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam at libero nec velit euismod consectetur. Nulla facilisi. Pellentesque placerat
\t \t \t sapien felis, sit amet auctor nisl eleifend ut. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel justo a turpis commodo laoreet scelerisque posuere odio. Duis pellentesque
\t \t \t metus sed egestas vestibulum. In elit ante, gravida sed hendrerit quis, dapibus quis felis.</p>
\t \t \t <p>Pellentesque commodo finibus tempus. Donec lobortis ut est sit amet imperdiet. Morbi et tortor at turpis dapibus vulputate. Curabitur ornare leo leo. In justo tortor, semper ac dui eu,
\t \t \t luctus gravida felis. Mauris dui diam, consectetur tincidunt aliquet vitae, tempus sed urna. Suspendisse facilisis, mauris sed dapibus suscipit, odio orci imperdiet est, in vulputate odio
\t \t \t lectus ut lacus. Curabitur eros dui, eleifend vel pretium vel, semper non felis. </p>
\t \t </div>
\t </body>
</html>
是您的「檢查登錄」腳本就像你指定的,或者是更長?請添加您用於登錄用戶的完整代碼。如果你只使用它,那麼課程用戶不會得到驗證。 – Eda190 2015-03-13 16:52:15
這就是我所有的代碼 – beckyboo 2015-03-13 16:52:49
我似乎無法找到有關您的數據庫結構的任何信息。沒有這些,我無法回答你的問題,因爲要登錄一個用戶,你必須將他/她輸入的數據與數據庫中的數據進行比較。 – Eda190 2015-03-13 16:54:37