Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    85
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Is this a secure way of doing things?

    I using Object-Oriented Programing and I think I'm finally getting the hang of things (I hope). However, I'm far from being a guru, but I just want to make sure I'm going in the right direction before I write tons of code: I think I'm going in the right direction.

    Here's what I have so far:

    PHP Code:
    <?php #register.php
    // Need the utilities file:
    require('includes/utilities.inc.php');
    // Will be eventually using $_SESSION or $_POST (Most likely $_POST) 
    $data = array(
                 
    'id' => '01',
                 
    'userType' => 'admin',
                 
    'username' => 'Frankenstein',
                 
    'pass' => '*****',
                 
    'email' => 'herman@munster.com',
                 
    'fullName' => 'Herman Munster',
                 
    'address' => '1313 Mockingbird Lane',
                 
    'city' => 'Monster City',
                 
    'state' => 'MI',
                 
    'zipCode' => '48150'        
                 
    );
    $user1 = new FormCheck();           
    foreach (
    $data as $property => $value) {           
        
    $user1->$property htmlspecialchars($value);
    }
    echo 
    '<pre>';
    print_r($user1);
    echo 
    '</pre>';
    if (
    $user1->isAdmin()) {
        echo 
    'Is an administrator<br>';
    }

    if (
    $user1->hasValidEmail()) {
        echo 
    $user1->email ' is a valid email address.<br>';
    }
    An here is my Class file:
    PHP Code:
    <?php 

    class FormCheck {
        
        private 
    $id=NULL;
        private 
    $userType=NULL;
        private 
    $username=NULL;
        private 
    $pass=NULL;
        private 
    $email=NULL;
        private 
    $fullName=NULL;
        private 
    $address=NULL;
        private 
    $city=NULL;
        private 
    $state=NULL;
        private 
    $zipCode=NULL;
        
        public function 
    __get($property) {
         if (
    property_exists($this$property)) {
             
           return 
    $this->$property;
         }
        }
      
        public function 
    __set($property$value) {
         if (
    property_exists($this$property)) {
     
           
    $this->$property $value;
         }
      
         return 
    $this;
        }

       
    // Method returns a Boolean if the users is an administrator:
       
    public function isAdmin() {
           return (
    $this->userType == 'admin');
       }

       
    // Method returns a Boolean indicating if the user is an administrator
       // or if the user is the original author of the provided page:
       
    public function canEditPage(Page $page) {
           return (
    $this->isAdmin() || ($this->id == $page->getCreatorId()));
       }
       
       
    // Method returns a Boolean if the user's email is valid:
       
    public function hasValidEmail() {
           return (
    filter_var($this->emailFILTER_VALIDATE_EMAIL));       
       }

    }
    I'm in not that big of rush for an answer/opinion and I do think I'm heading in the right direction, plus if any one wants to use this code feel free to use it.

    John
    Last edited by Strider64; 05-18-2013 at 05:23 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •