The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End OOP LogIn System

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #30062

    OK, I’m in need of a php genius..
    Sorry in advanced for the longnessnes of this post.

    I’m trying to create a login script for a website and since OOP seems to be all the rage these days i thought i might use it. But i seem to have got into some difficulties.

    This is the idea –
    Every page has the class ‘UserAccount’ set to a variable userAccount (creative i know). Anyway, this class then checks to see if the user is already logged in (if so it takes the data from the session and stores them as variables), if the login form has been sent via post to the page (if so if validates the data and logins in through mysql query) or whether is neither (in that case its someone viewing an ordinary page while not logged in).

    So, this is the class so far. What I am having trouble with is the validation of the email address and the password (that’s all they need to log in).

    So can someone please teach me how to validate them, i could do it if i was not using oop, i have lots of times, but now it just seems too hard.

    Before someone mentions it, i have read Chris’ tutorial on building an application from scratch but i just don;t understand the pdo stuff.

    Many Thanks In Advance for all of your time.

    So, at long last the code.

    class UserAccount
    private $_isLoggedIn;
    private $_isFormFilled;
    private $_userToken;
    private $_formErrors;

    private $_userMail;
    private $_userPassword;
    private $_userFirstName;
    private $_userLastName;
    private $_userID;

    public function __construct()
    $this->_isLoggedIn = (isset($_SESSION)) ? true : false;
    $this->_formErrors = array();

    ($this->_isLoggedIn) ? $this->getSessionData() : $this->isFormSent();

    private function getSessionData()
    $this->_userFirstName = $_SESSION;
    $this->_userLastName = $_SESSION;
    $this->_userID = $_SESSION;

    private function isFormSent()
    if(isset($_POST)) $this->checkInput();

    private function checkInput()
    throw new Exception('You Have Entered Invalid Characters In The Form.');

    throw new Exeption('Please Try Again Later, Or Contact Us For Help.')

    private function isDataValid()
    $this->_userMail = $this->filterInput($_POST);
    $this->_userPassword = $this->filterInput($_POST);
    return () ? true : false;

    private function filterInput($tempVar)
    return preg_replace('/[^a-zA-Z0-9]/','',$tempVar);

    private function checkToken()
    $this->_userToken = $_POST;
    return ($this->_userToken == $_SESSION) ? true : false;

    private function sendToDB()



    As you can see it’s all a bit dis-jointed but I am mainly seeking help on the data validation bit.
    Many Thanks

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.