user login form

  • bluegene
  • Born
  • Born
  • bluegene
  • Posts: 2

Post 3+ Months Ago

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 Code: [ Select ]
<?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>
 
  1. <?php
  2.     session_start();
  3.     if (!isset ($_POST['login']) || empty ($_POST['login'])) {
  4.    
  5.     require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
  6.     require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
  7.     }
  8. ?>
  9. <!DOCTYPE html>
  10. <html>
  11.   <head>
  12.     <title>cMail</title>
  13.     <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
  14.   </head>
  15.   <body>
  16.     <a href="/user/logout.php">Logout</a><br />
  17.     <a href="/account/create.php">Create Account</a><br />
  18.     <a href="/account/view.php">All Accounts</a><br />
  19.   </body>
  20. </html>
  21.  


this is the login.php file:

PHP Code: [ Select ]
<?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>
 
  1. <?php
  2.     session_start ();
  3.     require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/database.php');
  4.     require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/functions.php');
  5.     if (isset ($_POST['process']) && $_POST['process'] == '1') {
  6.         $login = login ($_POST['email'], $_POST['password']);
  7.         if ($login == false) {
  8.             $error = true;
  9.         } else {
  10.             $_SESSION['login'] = $login;
  11.             header ('Location: /');
  12.             exit();
  13.         }
  14.     }
  15. ?>
  16. <!DOCTYPE html>
  17. <html>
  18.   <head>
  19.     <title>cMail</title>
  20.     <link rel="stylesheet" type="text/css" href="/styles/stylesheet.css" />
  21.   </head>
  22.   <body>
  23.     <h1>Login</h1>
  24.     <?php if (isset ($error) && $error == true): ?>
  25.         <div class="error">There was an error while trying to log you in, please check your username/password.</div>
  26.     <?php endif; ?>
  27.     <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
  28.      <table>
  29.       <tr>
  30.        <td><label for="email">Email</label></td>
  31.        <td><input type="email" name="email" id="email" /></td>
  32.       </tr>
  33.       <tr>
  34.        <td><label for="password">Password</label></td>
  35.        <td><input type="password" name="password" id="password" /></td>
  36.       </tr>
  37.       <tr>
  38.        <td><input type="hidden" name="process" value="1" /></td>
  39.        <td><input type="submit" value="submit" /></td>
  40.       </tr>
  41.      </table>
  42.     </form>
  43.   </body>
  44. </html>
  45.  


this is the logout.php file:

PHP Code: [ Select ]
<?php
    session_start ();
    unset($_SESSION);
    header ('location: /user/login.php');
?>
 
  1. <?php
  2.     session_start ();
  3.     unset($_SESSION);
  4.     header ('location: /user/login.php');
  5. ?>
  6.  


this is the functions.php file:

PHP Code: [ Select ]
<?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;
    }
?>
 
  1. <?php
  2.     function login ($email, $password)
  3.     {
  4.         $mysql_select = "SELECT * FROM `user`
  5.                         WHERE `email` = '$email'
  6.                         AND `password` = MD5('$password')";
  7.         $mysql_query = mysql_query($mysql_select);
  8.         if ($mysql_query && mysql_num_rows ($mysql_query) > 0) {
  9.             while ($row = mysql_fetch_assoc ($mysql_query)) {
  10.                 return $row['id'];
  11.             }
  12.         }
  13.         return false;
  14.     }
  15. ?>
  16.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Could you post a little more information. Are you receiving any sort of error messages? Or does the page just seem to reload? Can you go into more details on what you want to happen, and what is happening. That should help you get a better response.

Thanks!

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 150 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.