What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » php login page

php login page
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
RE: php login page
I once made myselve this class to manage my login pages

[code]<?
class database_connection{

  var $query_id;
  var $link;

  function connect($location, $username, $password, $database){
    $this->link = mysql_connect($location, $username, $password) or die ("Could not Connect: ".mysql_error());
    mysql_select_db($database) or die ('Could not select database: '.mysql_error());
    Return true;
  }
  function query($query){
  $this->query_id = mysql_query($query) or die ('Query failed: '.mysql_error());
  Return true;
  }
  function output(){
    $array = mysql_fetch_array($this->query_id, MYSQL_ASSOC);
    Return $array;
  }
  function closelink(){
    if(!empty($this->query_id)){
      if(is_resource($this->query_id)){
        mysql_free_result($this->query_id);
      }
    }
    mysql_close($this->link);
  }
}


class loginmanager{
 
  function verify(){
    if(empty($_SESSION['ingelogd']) || $_SESSION['ingelogd'] != true){
      $this->makeloginscreen();
    }
  }
  function verify_ERR401(){
    if(empty($_SESSION['ingelogd']) || $_SESSION['ingelogd'] != true){
      header('HTTP/1.0 401 Unauthorized');
      die("HTTP/1.0 401 Unauthorized");
    }
  }
  function makeloginscreen(){
    $con = new database_connection();
    $con->connect("location", "user", "password", "database");
   
    if(isset($_POST['login']) && $_POST['login'] == "yes"){
      if(isset($_POST['username']) && $_POST['username'] != ""){
        $con->query("SELECT * FROM `login` WHERE `username` = '".$_POST['username']."'");
        $num = count($con->query_id);
        if($num <= 1){
          if($num >= 1){
            if(isset($_POST['password']) && $_POST['password'] != ""){
              $USER = $con->output();
              if(md5($_POST['password']) == $USER['password']){    //Succesvol ingelogd
                $_SESSION['ingelogd'] = true;
                $_SESSION['userid'] = $USER['id'];
                $_SESSION['username'] = $USER['username'];
                header("Location: index.php");
              }else{                                                //Onsuccesvol ingelogd
                $_SESSION['ingelogd'] = false;
                header("Location: index.php");
              }
            }
          }else{
            $_SESSION['ingelogd'] = false;
            header("Location: index.php");
          }
        }else{
          die("ERROR, contact the webmaster with your login username about this");
        }
      }
      $con->closelink();
    }elseif(isset($_SESSION['ingelogd']) && $_SESSION['ingelogd'] == true){
      header("Location: index.php");
    }else{
      echo "<form action=\"#\" method=\"post\">\n";
      echo "\t<table>\n";
      echo "\t\t<tr>\n\t\t\t<td>Username:</td>\n\t\t\t<td><input type=\"text\" name=\"username\"></input></td>\n\t\t</tr>\n";
      echo "\t\t<tr>\n\t\t\t<td>Password:</td>\n\t\t\t<td><input type=\"password\" name=\"password\"></input></td>\n\t\t</tr>\n";
      echo "\t\t<input type=\"hidden\" name=\"login\" value=\"yes\">\n";
      echo "\t\t<tr>\n\t\t\t<td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"submit\"></td>\n\t\t</tr>\n";
      echo "\t</table>\n</form>";
    }   
    die();
  }
}
?>[/code]

It also uses a database class I made to make easy database connections.

You can modify or just read the code and learn :)

BTW: To use, just include the page these classes are in and call the function verify() to see if the user is logged in, if he/she is she will she the page that is made under the verify() call else he/she will see the login form, and with verify_401(), they will see a black page with a 401 Unauthorized header sent to the browser.

EDIT: Reindented the code

This post was edited on 07-09-2006 at 09:39 PM by Ezra.
[Image: 1-0.png]
             
07-09-2006 09:27 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
php login page - by stoshrocket on 07-09-2006 at 09:17 PM
RE: php login page - by matty on 07-09-2006 at 09:19 PM
RE: php login page - by Ezra on 07-09-2006 at 09:27 PM
RE: php login page - by absorbation on 07-09-2006 at 09:49 PM
RE: php login page - by RaceProUK on 07-10-2006 at 10:44 AM
RE: php login page - by stoshrocket on 07-10-2006 at 11:07 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On