我一直有問題呼應我的$_SESSION['user_name']
。我注意到如果我刪除「!」從形式if語句如果登錄在或者被確定,它的第二次登錄後,工作原理:
if(!isset($_SESSION['LOGIN_STATUS'])
然而,儘管這是沒有意義的,我也禁用註銷功能,因此我儘量避免這種情況。我也想知道是否將用戶名填入單獨的表單中是否存在問題。
我也無法返回任何值$_SESSION['user_id']
。我嘗試過很多事情,包括使用PDO :: FETCH_NUM檢查拼寫,並驗證我的表格憑證,但仍然沒有任何結果。
PHP:
<?php
session_start();
require_once('php/config.php');
if(isset($_POST['submit'])){
$username = $_POST['user_name'];
$password = $_POST['pwd'];
$stmt = $con->prepare("SELECT * FROM tapp_login WHERE username = ? AND password = ? LIMIT 1");
$stmt->bind_param('ss', $username, $password);
$stmt->execute();
$stmt->bind_result($username, $password);
$stmt->store_result();
if($stmt->num_rows == 1){ //To check if the row exists
$row = $stmt->fetch(PDO::FETCH_NUM); //fetching the contents of the row
$_SESSION['LOGIN_STATUS']=true;
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['user_name'] = $username;
echo 'true';
}
else {
echo 'false';
}
$stmt->close();
}
else{
}
$con->close();
?>
FORM:
<body>
<fieldset id="login_form_wrap" class="login_form_header">
<legend><a href='projects.php'>CUSTOMER LOGIN</a></legend>
<?php session_start();
$_SESSION['timeout'] = time();?>
<div id="profile">
<!--If not logged in-->
<?php if(!isset($_SESSION['LOGIN_STATUS']) || ($_SESSION['timeout'] + 600 < time())){?>
<div id="login_a">
<a id="login_profile" href="#">click to login</a>
</div>
<!--Else if logged in-->
<?php }else {;?>
<a href='logout_session.php' id='logout'>Logout</a>
<!--header('location: dashboard.php');-->
<?php } ?>
</div>
<form action="login_validation.php" id="login_form" method="POST">
<div id="login_b">
<div class="welcome"></div>
<span class="col1">USER NAME:</span>
<input type="text" id="user_name" name="user_name" class="input" required />
<span class="col1">PASSWORD:</span>
<input type="password" id="password" name="password" class="input" required />
<span class="col1"></span>
<input type="submit" name"submit" id="login_validation" value="SUBMIT" />
<input type="reset" id="cancel_hide" value="CANCEL" />
<div id="add_err"><br></div>
</div>
</form>
<form action="project_validation.php" id="projects_form" method="POST">
<div id="projects">
<!-------------------------- Does not work ------------------------->
<div class="welcome">Welcome <?php echo $_SESSION['user_name'];?><br>
User ID: <?php echo $_SESSION['user_id'];?></div>
<span class="col1">PROJECTS:</span>
<select id="Projects" name="Projects" class="input">
<option id="project" name="project" value="" selected="selected" disabled='disabled'>Choose a Project...</option>
...
</select>
</div>
<span class="col1"></span>
<input type="submit" name="select" id="project_validation" value="SELECT" />
<div id="add_err"><br></div>
</form>
</fieldset>
</body>
截至目前,在當前代碼呼應$_SESSION['user_name']
和$_SESSION['user_id']
時,返回的用戶名和密碼,但沒有確認作品
如果您想知道「...」只是代表更多不必要的形式。
您需要先學習基礎知識。 –
@relentless也許如此..我是新來的,只是在正確的方向尋找一個點。 – Rob
我並沒有說過要阻止你,我說過因爲你的問題太大而無法在這裏回答。繼續嘗試。閱讀一些教程,觀看視頻等... –