Answer the question
In order to leave comments, you need to log in
PHP. How to fix the error? "Notice: Undefined variable: mysqli"?
Good afternoon. Please help me fix the error Notice: Undefined variable: mysqli
Notice: Undefined variable: mysqli in C:\xampp\htdocs\vik2\auth.php on line 39
<?php
include("dbconnect.php");
require_once 'auth.php';
// If post, check user
if (!empty($_POST['userlogin']) && !empty($_POST['pass'])) {
// Verify user and password
if (isValidUser($_POST['userlogin'], $_POST['pass'])) {
// Log in
$_SESSION['userlogin'] = $_POST['userlogin'];
header('Location: index.php');
exit();
}
else
{
$_SESSION['userlogin'] = FALSE;
}
}
// The user login page
include 'templates/header.php';
?>
<!--login modal-->
<div id="loginModal" class="modal show bs-example-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<form class="form" method="POST" action="login.php">
<div class="modal-header">
<h3 class="text-center">User authentication</h3>
</div>
<div class="modal-body">
<div class="form-group">
<input type="text" class="form-control input-sm" placeholder="login" name="userlogin">
</div>
<div class="form-group">
<input type="password" class="form-control input-sm" placeholder="password" name="pass">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default">Login</button>
</div>
</form>
</div>
</div>
</div>
<?php
include 'templates/footer.php';
<?php
session_start();
include("dbconnect.php");
function authHTML()
{
// if not auhtenticaded session go to login.php
if (empty($_SESSION['userlogin'])) {
header('Location: login.php');
exit();
}
}
function authAPI()
{
$user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$pass = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
if (!isValidUser($user, $pass)) {
$_SESSION['userlogin'] = FALSE;
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
die("Not authorized");
}
$_SESSION['userlogin'] = $user;
}
function isValidUser($user, $pass)
{
$testrole = $mysqli->query("SELECT * FROM `users` WHERE username = '".$user."' AND password = '".$pass."'");
if($testrole->num_rows == 1){
return TRUE;
}
return FALSE;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question