Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Hi, i need a private messaging system. the ones i'v tried dont seem to work....
    here goes.

    data base is all set up

    class.login.php
    PHP Code:
    <?php

    class Login
    {
      private 
    $_id;
      private 
    $_username;
      private 
    $_password;
      private 
    $_passmd5;

      private 
    $_errors;
      private 
    $_access;
      private 
    $_login;
      private 
    $_token;

      public function 
    __construct()
      {
        
    $this->_errors = array();
        
    $this->_login  = isset($_POST['login'])? 0;
        
    $this->_access 0;
        
    $this->_token  $_POST['token'];

        
    $this->_id      0;
        
    $this->_username = ($this->_login)? $this->filter($_POST['username']) : $_SESSION['username'];
        
    $this->_password = ($this->_login)? $this->filter($_POST['password']) : '';
        
    $this->_passmd5  = ($this->_login)? md5($this->_password) : $_SESSION['password'];
      }

      public function 
    isLoggedIn()
      {
        (
    $this->_login)? $this->verifyPost() : $this->verifySession();

        return 
    $this->_access;
      }

      public function 
    filter($var)
      {
        return 
    preg_replace('/[^a-zA-Z0-9]/','',$var);
      }

      public function 
    verifyPost()
      {
        try
        {
          if(!
    $this->isTokenValid())
            throw new 
    Exception('Invalid Form Submission');

          if(!
    $this->isDataValid())
            throw new 
    Exception('Invalid Form Data');

          if(!
    $this->verifyDatabase())
            throw new 
    Exception('Invalid Username/Password');

        
    $this->_access 1;
        
    $this->registerSession();
        }
        catch(
    Exception $e)
        {
          
    $this->_errors[] = $e->getMessage();
        }
      }

      public function 
    verifySession()
      {
        if(
    $this->sessionExist() && $this->verifyDatabase())
          
    $this->_access 1;
      }

      public function 
    verifyDatabase()
      {
        
    //Database Connection Data
        
    mysql_connect("ip""username""pass") or die(mysql_error());
        
    mysql_select_db("db") or die(mysql_error());

        
    $data mysql_query("SELECT ID FROM users WHERE username = '{$this->_username}' AND password = '{$this->_passmd5}'");

        if(
    mysql_num_rows($data))
          {
            list(
    $this->_id) = @array_values(mysql_fetch_assoc($data));
            return 
    true;
          }
        else
          { return 
    false; }
      }

      public function 
    isDataValid()
      {
        return (
    preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_username) && preg_match('/^[a-zA-Z0-9]{5,12}$/',$this->_password))? 0;
      }

      public function 
    isTokenValid()
      {
        return (!isset(
    $_SESSION['token']) || $this->_token != $_SESSION['token'])? 1;
      }

      public function 
    registerSession()
      {
        
    $_SESSION['ID'] = $this->_id;
        
    $_SESSION['username'] = $this->_username;
        
    $_SESSION['password'] = $this->_passmd5;
      }

      public function 
    sessionExist()
      {
        return (isset(
    $_SESSION['username']) && isset($_SESSION['password']))? 0;
      }

      public function 
    showErrors()
      {
        echo 
    "<h3>Errors</h3>";

        foreach(
    $this->_errors as $key=>$value)
          echo 
    $value."<br>";
      }
    }

    ?>
    Table USER structure

    Code:
    CREATE TABLE `users` (
      `ID` int(75) NOT NULL auto_increment,
      `username` varchar(15) NOT NULL,
      `password` varchar(45) NOT NULL,
      `email` varchar(44) NOT NULL,
      `age` varchar(2) NOT NULL,
      UNIQUE KEY `ID` (`ID`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
    Please.... if there is anything missing please tell me.... i really need this.

    Thanks!

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    So what you have now is the user's MySQL table and a login script. That's all.

    What about the rest of it? Are you looking for a script, or some suggestions?
    What is the private message supposed to do? Is there an admin thing involved?
    This could end-up being a big project, but you only have the login part right now.


  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    55
    Member #
    31209
    Yes, I would like a script. i dont need anything fancy, just a subject, to, and from forum. inbox, a way to delete message. i can figure out how to display friends.

    can u help me?

  5. #4
    CPD
    CPD is offline
    Member
    Join Date
    May 2012
    Location
    South London, England
    Posts
    36
    Member #
    31775
    Liked
    5 times
    I'm new to the forum but will hazard a guess as to people not writing scripts for you, they're here to help you improve on your knowledge and extend your understanding.

    Re. the OP: As already said a private messaging system has the potential to be quite big. If you want a very basic PM system you need a lot more than you've already got.

    Firstly, you need to start from the database and think about how your going to structure your tables. In order to do this you must have a clear set of requirements your system must have for you to accomplish your goal. In a basic sense these requirements could be
    • Create new messages
    • Reply to messages
    • Send message to multiple people
    • Messages marked as read.

    In which case your database could have 3 tables: Users, Messages, MessagesAccess. Users you already have. Messages contains any message any user sends. MessagesAccess contains the ID of a message and the ID of any user who's able to read that message along with a "read" field indicating whether or not they've read the message.

    This heads towards a simple messaging system with a relational database. Regarding your application logic, well that depends on how you set your database which inherently depends on your requirements.
    AlphaMare likes this.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:23 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com