The following code works on my university server just fine but doesn't work on a private one that I have paid for.
The problem lies in the:
header("Location: products.php");
}
} else {
echo "Invalid username or password!";
}
If I enter the wrong name/password the code echo's as expected. But if the user enters their details correctly, nothing happens at all!
I am new to PHP so I don't know where to start to troubleshoot but I have tried replacing the "header("Location: products.php");" with an echo but with no avail still.
I have also considered that the PHPmyadmin servers might be different versions or the character encoding might be causing some of this trouble.
Here is the full code.
Any help would be absolutely appreciated!
<?php
if(isset($_POST["submit"])){
$user=$_POST['user'];
$pass=$_POST['pass'];
$username = "";
$password = "";
$hostname = "";
$md5pass = md5($pass);
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password);
$con=mysql_connect($hostname, $username, $password) or die(mysql_error());
$select=mysql_select_db("l1233156", $con) or die("cannot select DB");
$query=mysql_query("SELECT * FROM login WHERE username='".$user."' AND password='".$md5pass."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $md5pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: products.php");
}
} else {
echo "Invalid username or password!";
}
}
?><!doctype html>
<html>
<head>
<title>Login</title>
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<div class="center">
<p><a href="register.php">Register</a> | <a href="login.php">Login</a></p>
<h3>Login Form</h3>
<form action="" method="POST">
Username: <input type="text" name="user"><br />
Password: <input type="password" name="pass"><br />
<input type="submit" value="Login" name="submit" />
</form>
</div>
</body>
</html>
EDIT: This is what I managed to grab from the error logs.
[Mon Jul 14 10:30:34.134187 2014] [autoindex:error] [pid 28718:tid 140153014126336] [client 86.153.7.34:55032] AH01276: Cannot serve directory /home/joesadmin123/public_html/productreviews/: No matching DirectoryIndex (index.html.var,index.htm,index.html,index.xhtml,index.wml,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.php4,index.php3,index.php,index.phtml,index.shtml,default.htm,default.html,home.htm,index.php5,Default.html,Default.htm,home.html,welcome.html) found, and server-generated directory index forbidden by Options directive