I have a login page, and when they click login, it goes to verify login, which is below:
<?php
include('loginConfig.php');
// making the usernames from the form a variable
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
// To not get injected....
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//SQL!
$sql = "SELECT * FROM `members` WHERE username = '$username' and password = '$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($Success == 1){
session_start();
$_SESSION['loggedin'] = 'true';
$_SESSION['username'] = '$username';
header("Location: ../member.php");
include('../include/blank.php');
}
//Incorrect Loggin !
else {
Global $Title; $Title = "Failed Loggin"
Global $Content; $Content="Incorrect Username or Password. Please check your credentials, and try again later.";
include('../include/blank.php');
}
?>
In my database connect file, if Success=1, it establishes the link ID. So, in my code, if Success=1, it should set the sessions, and the usernames, and then redirect to …/member.php. However, its not. Can you look at it and see if you can figure it out?
<?php
$host = "localhost"; // host, usually localhost
$username = "***"; // database username
$password = "*******"; // database password
$default_dbname = "*****";
function db_connect() {
global $Success ;
$Success = 0;
global $dbhost, $dbuser, $dbpassword;
$link_id = mysql_connect($host, $username, $password);
if(!$link_id) {print("<p id='error'>Connection failed to the host $dbhost.</p>");"";
}
else $Success = 1;
return $link_id;
}
mysql_query($con);
$con = mysql_connect("$host", "$username", "$password") or die("cannot connect to MySQL"); // connecting to MySQL
if($con) {
echo 'it works';
} else {
echo 'wtf?!';
}
mysql_select_db("$default_dbname") or die ("cannot select database, please check your mysql settings"); // selecting the MySQL database
?>
I tested my connection, and I know I am connected…