Anytime i try to login in with my login file it gives me the error which is set in the code, but i cannot figure out what is wrong with it.
Here's my code:
<?php
include 'inc/dbc.php';
include 'inc/functions.php';
?>
<?php
function get_client_ip() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP']) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
}
else if($_SERVER['HTTP_X_FORWARDED_FOR']) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else if($_SERVER['HTTP_X_FORWARDED']) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
}
else if($_SERVER['HTTP_FORWARDED_FOR']) {
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
}
else if($_SERVER['HTTP_FORWARDED']) {
$ipaddress = $_SERVER['HTTP_FORWARDED'];
}
else if($_SERVER['REMOTE_ADDR']) {
$ipaddress = $_SERVER['REMOTE_ADDR'];
}
else {
$ipaddress = 'UNKNOWN';
}
return $ipaddress;
}
?>
<?php
if(isset($_GET['user']) && !empty($_GET['user'])) {
$username = $_GET['user'];
} else {
$username = $_SESSION['username'];
}
$my_name = $_SESSION['username'];
$firstname = getuser($username, 'firstname');
$middlename = getuser($username, 'middlename');
$lastname = getuser($username, 'lastname');
$aboutme = getuser($username, 'aboutme');
$email = getuser($username, 'email');
$dob = getuser($username, 'dob');
$address = getuser($username, 'address');
$website = getuser($username, 'website');
$country = getuser($username, 'country');
$city = getuser($username, 'city');
$state = getuser($username, 'state');
$phone = getuser($username, 'phone');
$gender = getuser($username, 'gender');
$rank = getuser($username, 'rank');
$avatar = getuser($username, 'aavtar');
?>
<!DOCTYPE html>
<html>
<head>
<title>EWC Login</title>
<link rel="stylesheet" type="text/css" href="css/login.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
</head>
<body>
<div class='main'>
<div class='body'>
<div class="loginf">
<?php
if (loggedIn() == true) {
?>
<div class='logged'>
<div class='logwrapper'>
<div class='top'>
<p>Is this you? <a href="home.php">Home</a></p>
</div>
<div class='img'>
<img src="images/users/<?php echo $avatar;?>">
</div>
<div class='info'>
<h3><?php echo $firstname . ' ' . $middlename . ' ' . $lastname;?></h3>
<div class='subinfo'>
<?php echo $gender;?>
<?php echo $dob;?>
<?php echo $rank;?>
<?php echo $country . ', ' . $city . ' ' . $state; ?>
</div>
</div>
<div class='bottom'>
<p>You are already logged in. Click here to <a href="logout.php">logout.</a></p>
</div>
</div>
</div>
<?php
} else {
?>
<form method="post">
<?php
if (isset($_POST['submit'])) {
$username = stripcslashes(mysqli_real_escape_string($mysqli, $_POST['username']));
$password = stripcslashes(mysqli_real_escape_string($mysqli, $_POST['password']));
$pw = sha1($password);
if (empty($username) && empty($password)) {
echo 'Username and Password cannot be empty';
} else {
$check_login = mysqli_query($mysqli, "SELECT * FROM users WHERE username = '$username' AND password = '$pw' LIMIT 1") or die(mysqli_error($mysqli));
$rows = mysqli_num_rows($check_login);
if ($rows == 1) {
mysqli_query($mysqli, "UPDATE users SET login_ip = '$ipaddress' WHERE username = '$username' ") or die(mysqli_error($mysqli));
$_SESSION['username'] = $username;
header('location: home.php');
} else {
echo 'Your entries are Invalid';
}
}
}
?>
<div class="input-group margin-bottom-sm">
<span class="input-group-addon"><i class="fa fa-user fa-fw"></i></span>
<input class="form-control" name='username' type="text" placeholder="Username..."> <a href="forgot.php?forgot=username">Forgot Username?</a>
</div>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input class="form-control" name='username' type="password" placeholder="Password..."> <a href="forgot.php?forgot=password">Forgot Passowrd?</a>
</div>
<div class="input-group">
<input class="form-control" name="submit" type="submit" value="Login"> <a href="register.php">Don't have an account?</a>
</div>
</form>
<?php
}
?>
<script>
function clearAutofill() {
if ( navigator.userAgent.toLowerCase().indexOf('chrome') >= 0 ) {
$('input[autocomplete="off"]').each( function(){
$(this).val('');
});
}
}
setTimeout(clearAutofill,500);
</script>
</div>
</div>
</div>
</body>
</html>
PS: session_start(); is in the functions file! Also if you need more code please ask! Thanks in advance.