我知道在SO中有這麼多的問題。但是,我所擁有的代碼與此有點不同。在索引頁面顯示用戶名
我所擁有的是登錄頁面,我必須首先登錄才能進入索引頁面。
首先,我想說,我從某人那裏得到的這段代碼在幾天前沒有工作。但是,當我今天再次檢查它時,現在令人難以置信。
所以,今天我有兩個問題在這裏,具體如下:
- 我要顯示在索引頁的用戶信息。其實我只想顯示用戶名。但是,由於數據庫表中沒有用戶名行,因此如果它只能顯示用戶電子郵件,我會接受它。
- 我想在這裏也有專家審查我的代碼。正如我上面提到的,前幾天的代碼不起作用。今天,它沒有我改變的單一事物。
這裏最重要的問題是,問題數之一,是向用戶展示信息。
這裏是我的代碼:
1的index.php
<?php
include('UserSessionAdmin.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DASHBOARD</title>
<link rel="stylesheet" type="text/css" href="css.css"/>
</head>
<body>
<?php echo "$myemail";?>
2. UserSessionAdmin.php
<?php
session_start();
if ($_SESSION['login_id'] == 0 || $_SESSION['login_id'] == '') {
header('location: login.html');
exit();
}
require_once('configPDO.php');
?>
3的login.html
<div id="login-form">
<form method="post" action="CheckLogin.php">
<span class="identity">E-mail</span>
<input type="text" id="myemail" name="myemail" class="text" />
<span class="identity">Password</span>
<input type="text" id="mypassword" name="mypassword" class="text" />
<p id="button">
<input type="submit"/></p>
</form>
</div>
4. CheckLogin.php
<?php
// Start Session because we will save some values to session varaible.
session_start();
include("configPDO.php");
$myemail=$_POST['myemail'];
$mypassword=$_POST['mypassword'];
$STM = $dbh->prepare("SELECT * FROM user WHERE myemail = :myemail AND mypassword = :mypassword");
$STM->bindParam(':myemail', $myemail);
$STM->bindParam(':mypassword', $mypassword);
$STM->execute();
$count = $STM->rowCount();
$row = $STM -> fetch();
if($count==1)
{
$_SESSION['login_id']=$row['id'];
if($_SESSION['login_id'] == 1) {
header("location:index.php");
}
else {
header("location:login3.html");
}
}
else
{
header("location:login4.html");
}
$dbh = null;
?>
謝謝你的幫助。歡呼和問候,
你的index.php使用不是甚至定義的變量。你必須在你的會話中設置用戶信息,以在你的index.php中顯示它們。你在非常基礎上掙扎。 – 2014-10-01 08:52:33
@eeK這就是我想知道的。 :) – 2014-10-01 08:53:46
您可以像設置用戶的ID一樣設置電子郵件($ _SESSION ['email'] = $ row ['email'];),其中$ row ['email']表示列名你想使用的表格。在你的index.php中,你可以輸出你的$ _SESSION ['email']。 – 2014-10-01 08:57:06