-3
當您在我的網站上登錄時,腳本使用mysqli_real_escape_string
並且處理登錄。爲什麼stripslashes沒有斜線不返回數據?
例如,當您在主頁上按下登錄按鈕時,網站將轉到該文件。如果一切順利,您將被重定向到開始頁面,但是如果出現問題,您將停留在此頁面並看到一個表單。表格中包含您在按下登錄前輸入的數據。該數據最後包含斜線。
我想通過使用stripslashes
刪除斜槓,所以我創建了一個名爲slash
的函數來刪除它們,但是當您輸入錯誤的東西時,我仍然看到斜槓。
//the slash function is placed in a previous loaded file
function slash($username, $password){
$password = stripslashes($password);
$username = stripslashes($username);
return $username;
return $password;
}
if(empty($_POST === false)){
$username = $_POST['username'];
$password = $_POST['password'];
//check if the fields are empty
if (empty($username) || empty($password)){
$errors[] = 'You need to enter a username and password';
//check if the username exists
}else if(user_exists($username) === false){
$errors[] = 'We can\'t find that username';
slash($username, $password);
//check if the username is active
}else if(user_active($username) === false){
$errors[] = 'You haven\'t activated your account';
slash($username, $password);
//if none of the previous checks are false, log in
}else{
$login = login($username, $password);
//if username or password is incorrect, display error
if($login === false){
$errors[] = 'That username or password combination is incorrect';
slash($username, $password);
//if everthing is fine, log in
}else{
//set the user session
$_SESSION['user_id'] = $login;
//redirect user to home
header('Location: index.php');
exit();
}
}
}
?>
<html>
<head>
<link rel="stylesheet" href="css/error_login.css"/>
</head>
<body>
<?php
include 'templates/menu/menu.php';
?>
<div class="error_login">
<h3>Login</h3>
<form action="login.php" method="POST">
<div id="login">
username:<br>
<input type="text" name="username" value=<?php echo $username; ?>/><br><br>
password:<br>
<input type="password" name="password" value=<?php echo $password; ?>/><br><br>
<input type="submit" value="Log In"/><br><br>
<a href="register.php">Register</a>
<ul>
<?php
error_output($errors);
?>
</ul>
</div>
</form>
</div>
<?php
include 'templates/footer/footer.php';
?>
</body>
</html>
編輯
input:
username: test
password:
輸入就像你看到無效,因爲沒有密碼,所以該網站將重新顯示與userinput +增加的斜線形式
output:
username: test/
password: ●
你的函數有2個'return'語句。 '如果從一個函數內部調用,return語句立即結束當前函數的執行'(http://php.net/manual/en/function.return.php) –
你實際上並不知道在哪裏/在哪個點你正在看和看到斜線/ –
我們可以看到表單的HTML代碼嗎? –