Trying to access array offset on value of type bool in PHP 7.4
Easy with PHP ??
null coalescing operator
return $Row['Data'] ?? 'default value';
Or you can use as such
$Row['Data'] ??= 'default value';
return $Row['Data'];
PDO Trying to access array offset on value of type bool
You could do something like. However it does not protect against unsecure password nor timing attacks.
<?php
$nm = $_POST['nm'];
$pw = $_POST['pw'];
try{
$pdo = new PDO('mysql:host=localhost;dbname=gold-market_main', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e) {
echo "Connection failed: ".$e->getMessage();
die();
}
if($nm == null){
die("Feld darf nicht leer sein!")
} //ctype does not protect
$sql = $pdo->prepare("SELECT k_nutzername, k_passwort FROM kunden WHERE k_nutzername = ?;");
$sql->bindValue(1,$nm,PDO::PARAM_STR); //bind a value to a query, called parametrized queries, most secure way against SQL injection.
$sql->execute();
$row = $sql->fetch(PDO::FETCH_ASSOC);
if(!$row) { // if the username not exists
//header("Location: login_wrongUN.html");
print("nm wrong");
} elseif($row['k_passwort'] != $pw) {
//header("Location: login_wrongPW.html");
print("pw wrong");
} else {
header("Location: konto.html");
}
$pdo = null;
?>
Warning: Trying to access array offset on value of type bool
You problem is that get_user_hash
method will return false
when there is no such user with provided username.
You should consider to change your code to:
if(!empty($user) && $this->password_verify($password,$user['password']) == 1){
Related Topics
Zf2 - Get Controller Name into Layout/Views
Split a Text into Single Words
How to Execute PHP with Extension File.Php.Jpg
Hide Variation Info from Cart Item Title in Woocommerce 3+
How to Obtain a Nested HTML List from Object's Array Recordset
Mod_Rewrite, PHP and the .Htaccess File
Backreference Does Not Work in PHP
PHP Re-Order Array of Month Names
How to Access Magento User's Session from Outside Magento
PHP MySQL Greek Letters Showing Like? Marks
Use Git Smudge/Clean to Replace File Contents
Call PHP from Virtual/Custom "Web Server"
Dynamic Shipping Fee Based on Custom Radio Buttons in Woocommerce
PHP on Godaddy Linux Shared Trying to Send Through Gmail Smtp