hi can anyone just point me in the right direction, an let me know if this code is done rite or what can be wrong because its not working.
this is the index.php file:
<?php
session_start();
if (!isset ($_POST['login']) || empty ($_POST['login'])) {
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>cMail</title>
<link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
</head>
<body>
<a href="/user/logout.php">Logout</a><br />
<a href="/account/create.php">Create Account</a><br />
<a href="/account/view.php">All Accounts</a><br />
</body>
</html>
- <?php
- session_start();
- if (!isset ($_POST['login']) || empty ($_POST['login'])) {
-
- require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
- require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>cMail</title>
- <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
- </head>
- <body>
- <a href="/user/logout.php">Logout</a><br />
- <a href="/account/create.php">Create Account</a><br />
- <a href="/account/view.php">All Accounts</a><br />
- </body>
- </html>
-
this is the login.php file:
<?php
session_start ();
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
if (isset ($_POST['process']) && $_POST['process'] == '1') {
$login = login ($_POST['email'], $_POST['password']);
if ($login == false) {
$error = true;
} else {
$_SESSION['login'] = $login;
header ('Location: /');
exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>cMail</title>
<link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
</head>
<body>
<h1>Login</h1>
<?php if (isset ($error) && $error == true): ?>
<div class="error">There was an error while trying to log you in, please check your username/password.</div>
<?php endif; ?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<table>
<tr>
<td><label for="email">Email</label></td>
<td><input type="email" name="email" id="email" /></td>
</tr>
<tr>
<td><label for="password">Password</label></td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td><input type="hidden" name="process" value="1" /></td>
<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
- <?php
- session_start ();
- require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
- require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
- if (isset ($_POST['process']) && $_POST['process'] == '1') {
- $login = login ($_POST['email'], $_POST['password']);
- if ($login == false) {
- $error = true;
- } else {
- $_SESSION['login'] = $login;
- header ('Location: /');
- exit();
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>cMail</title>
- <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
- </head>
- <body>
- <h1>Login</h1>
- <?php if (isset ($error) && $error == true): ?>
- <div class="error">There was an error while trying to log you in, please check your username/password.</div>
- <?php endif; ?>
- <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
- <table>
- <tr>
- <td><label for="email">Email</label></td>
- <td><input type="email" name="email" id="email" /></td>
- </tr>
- <tr>
- <td><label for="password">Password</label></td>
- <td><input type="password" name="password" id="password" /></td>
- </tr>
- <tr>
- <td><input type="hidden" name="process" value="1" /></td>
- <td><input type="submit" value="submit" /></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
-
this is the logout.php file:
<?php
session_start ();
unset($_SESSION);
header ('location: /user/login.php');
?>
- <?php
- session_start ();
- unset($_SESSION);
- header ('location: /user/login.php');
- ?>
-
this is the functions.php file:
<?php
function login ($email, $password)
{
$mysql_select = "SELECT * FROM `user`
WHERE `email` = '$email'
AND `password` = MD5('$password')";
$mysql_query = mysql_query($mysql_select);
if ($mysql_query && mysql_num_rows ($mysql_query) > 0) {
while ($row = mysql_fetch_assoc ($mysql_query)) {
return $row['id'];
}
}
return false;
}
?>
- <?php
- function login ($email, $password)
- {
- $mysql_select = "SELECT * FROM `user`
- WHERE `email` = '$email'
- AND `password` = MD5('$password')";
- $mysql_query = mysql_query($mysql_select);
- if ($mysql_query && mysql_num_rows ($mysql_query) > 0) {
- while ($row = mysql_fetch_assoc ($mysql_query)) {
- return $row['id'];
- }
- }
- return false;
- }
- ?>
-