Okay I've fixed the segment of code but nothing has changed and it still doesn't work.
This is the code for all the files involved in my login.
I don't know why it doesn't work but I believe the problem is either with the header or membership.php files.
login.php
Code:
<?php
require_once 'classes/membership.php';
$membership = new membership();
// If the user clicks the "Log Out" link on the index page.
if(isset($_GET['status']) && $_GET['status'] == 'loggedout') {
$membership->log_user_out();
}
// Did the user enter a password and click submit?
if($_POST && !empty($_POST['pwd'])) {
$response = $membership->validate_user($_POST['pwd']);
} else if(isset($_POST['enter'])){
if($_POST && empty($_POST['pwd'])) {
$response2 = "Please enter a code.";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/main.css"/>
<title>
Design Explosions · Sign In
</title>
<script type="text/javascript" src="javascript/mootools.js"></script>
<script type="text/javascript" src="javascript/imageMenu.js"></script>
</head>
<body>
<div id="page-wrap">
<?php include ("header.php"); ?>
<div id="inside">
<?php include ("menu.php"); ?>
<script type="text/javascript">
window.addEvent('domready', function(){
var myMenu = new ImageMenu($$('#imageMenu a'),{openWidth:310, border:0, onOpen:function(e,i){window.location=(e);}});
});
</script>
<div id="main-body">
<form name="input" method="post" action="">
<div id="login_table_wrap">
<div id="login_title">
<h3>Account Sign In<h3><br/><small>Sign in using the form below and you'll be ready to upload and view your own artwork.</small>
</div>
<table>
<tr>
<td class="login_pass">
Code:
</td>
<td class="input">
<input type="password" name="pwd"/>
</td>
</tr>
<tr>
<td class="login_enter" colspan="2">
<input type="submit" value="Enter" name="enter" id="enter"/>
</td>
</tr>
</table>
</div>
</form>
<?php if(isset($response)) echo "<h4 class='alert'>" . $response . "</h4>"; ?>
<?php if(isset($response2)) echo "<h4 class='alert'>" . $response2 . "</h4>"; ?>
</div>
<?php include ("footer.php"); ?>
</div>
</div>
</body>
</html>
header.php
Code:
<?php
require_once 'classes/membership.php';
?>
<div id="header">
<div class="header-left">
BANNER GOES HERE
</div>
<div class="header-right">
<div id="signin">
<?php
if(isset($_SESSION['pwd'])) {
print '<a href="login.php?status=loggedout">Log Out</a>';
} else {
print '<a href="login.php"><img src="images/signin_button.jpg" border="0"></a>';
}
?>
</div>
</div>
</div>
usergallery.php
Code:
<?php
require_once 'classes/membership.php';
$membership = new membership();
$membership->confirm_member();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/main.css"/>
<title>
Design Explosions · Your Gallery
</title>
<script type="text/javascript" src="javascript/mootools.js"></script>
<script type="text/javascript" src="javascript/imageMenu.js"></script>
</head>
<body>
<div id="page-wrap">
<?php include("header.php"); ?>
<div id="inside">
<?php include("menu.php"); ?>
<script type="text/javascript">
window.addEvent('domready', function(){
var myMenu = new ImageMenu($$('#imageMenu a'),{openWidth:310, border:0, onOpen:function(e,i){window.location=(e);}});
});
</script>
<div id="main-body">
<div id="user_image_gallery">
IMAGE GALLERY
<a href="login.php?status=loggedout">Log Out</a>
</div>
</div>
<?php include ("footer.php"); ?>
</div>
</div>
</body>
</html>
membership.php
Code:
<?php
session_start();
require 'classes/mysql.php';
class membership {
function validate_user($pwd) {
$mysql = new mysql();
$ensure_credentials = $mysql->verify_pwd($pwd);
if($ensure_credentials) {
$_SESSION['status'] = 'authorized';
header("location: user_gallery.php");
} else return "Sorry that code does not exist.";
}
function confirm_member() {
if($_SESSION['status'] !='authorized') header("location: login.php");
}
function log_user_out() {
if(isset($_SESSION['status'])) {
unset($_SESSION['status']);
if(isset($_COOKIE[session_name()]))
setcookie(session_name(), '', time() - 1000);
session_destroy();
}
}
}
mysql.php
Code:
<?php
require_once 'includes/constants.php';
class mysql {
private $conn;
function __construct() {
$this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or
die('There was a problem connecting to the database.');
}
function verify_pwd($pwd) {
$query = "SELECT *
FROM users
WHERE password = ?
LIMIT 1";
if($stmt = $this->conn->prepare($query)) {
$stmt->bind_param('s', $pwd);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
}
}
constants.php
Code:
<?php
/**
* Databse Constants - these constants are required
* in order for there to be a successful conection
* to the MySQL database.
*/
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'membership');
?>
Bookmarks