Activity Stream
48,167 MEMBERS
63060 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 10 of 10
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default [PHP] Discussion (System Building)

    This thread is mainly to try and help guide the lost sheep in the right direction when it comes to PHP and building systems securely.

    Now you all probably think that I'm real good at PHP but I'm not, what im good at is understanding architecture.

    What i mean by architecture is summarized in these key points

    • Functional/logic view
    • Code/module view
    • Development/structural view
    • Concurrency/process/thread view
    • Physical/deployment view
    • User action/feedback view
    • Data view


    From this list you will see that an application is more that an if statement here and and else statement there, its about writing code in a way that it can be used for multiple purposes and have a more abstract approach to things.

    now if i refer to you as a noob do not take it personally if you write code at a lower level, theres still time to save you, but noobs are everywhere and they create sites that are error prone and unsecured and unstable.

    this is why everyday somebody in this forum posts a topic regarding asome shitty php code and saying help me fix it, as you notice us programmers such as jayfella hyperz and me get annoyed because its hard to fix a peice of code thats written poorly.

    so firstly im going to explain how a noob would create a small website and how it can be dramatically changed to a more stable and less error prone system.

    ----

    Site Name: My Mini Blog
    Site Desc: Small blog
    Created By: A Noob

    the noob would firstly start placing all his html into into index.php with some sample posts in there aswell, so he can see where he wants his code.

    then after he has the design how he wants it it will cut out the html posts and place some php tags there, connect to the database and start running queries

    then he will create another page call addpost.php and do the exact same as in the first page

    not this is not smart atall, this means that if he wants to make a change to lets say the database he would have to go throughout each file and do lots of edits.

    ok so lets talk about how a professional programmer would accomplish the same thing!

    he would create a set of files that store configurations such as datbase credentials, error settings, security, options etc.

    he would then create a small database layer,security layer,error layer, etc etc

    this would give him the flexibility to make 1 change to his database layer and that would change for the whole application.

    For example

    PHP Code: 
    class MySql extends mysqli
    {
        public function 
    __construct($host,$user,$pass,$db)
        {
             
    parent::__construct($host,$user,$pass,$db);
        }

    now that to me is perfect for a database start, as its extedning mysql, you instantly have a full database class based on mysql!

    ok so lets say that you want to have a prefic for your tables so you can do

    Code: 
    SELECT * FROM #__users WHERE userid = 1
    so that #__ gets turned into your prefix, well you can just create the same function thats in mysqli and work on the values before hand

    PHP Code: 
    public function query($query$result_mode MYSQLI_STORE_RESULT)
    {
         
    $querystr_replace("#__","myPrefix_",$query);
         return 
    parent::query($query,$result_mode);

    Now im not saying that you understand all the php functions because theres a hell of a lot im still learning, but my point is that don't be afraid to work solely with PHP to develop a stable system for your site to run on!

    if you have any questions about building a system like this and how to start it, just ask your questions and ill try and help

    also do not be afraid of making mistakes, if you kept doing the way you know is wrong but it works, then you will never ever learn.
    litewarez Reviewed by litewarez on . [PHP] Discussion (System Building) This thread is mainly to try and help guide the lost sheep in the right direction when it comes to PHP and building systems securely. Now you all probably think that I'm real good at PHP but I'm not, what im good at is understanding architecture. What i mean by architecture is summarized in these key points Functional/logic view Code/module view Development/structural view Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    Nice post..
    Now please guide me in this..
    I have written some code in php , which uses cURL and gets information from an API in json format, then I am decoding it , and storing it in variables.., when I need to show the value of a variable to the users , I am embedding php tags in html, which I think is not good..so do you suggest me to use some kind of template engine ??
    I want to avoid smarty , but rather make a small template engine myself..

    Thanks
    Coding Horror Fan
    I don't read PM's frequently .

  4.     
    #3
    Member
    What I do instead of building a whole framework for sites I code, I use the phpBB3 code as a framework, because I like how it works, with support for utf8, multibyte and other things. Also, using their DBAL is great for multiple types of database systems.

    EDIT: Just noticed your example, why don't you use PDO instead of creating a whole new class?

  5.     
    #4
    Member
    Website's:
    Doxsters.net
    Hm nice post, It got me thinking.
    Also, I'm thinking of learning OOP PHP, do you have any tips? I've never done OOP before

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):timtamboy63@gmail.com

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  6.     
    #5
    Retired NinJa
    Website's:
    loledhard.com
    Quote Originally Posted by timtamboy63 View Post
    Hm nice post, It got me thinking.
    Also, I'm thinking of learning OOP PHP, do you have any tips? I've never done OOP before
    OOP concepts are too vast. You need to take a Book to learn abt it



    You don't hate Justin bieber.You hate the fact you ain't Justin Bieber!

  7.     
    #6
    Member
    Website's:
    Doxsters.net
    I'm sure i'll manage with the internet

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):timtamboy63@gmail.com

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  8.     
    #7
    Retired NinJa
    Website's:
    loledhard.com
    ^ May be this would help u
    http://www.gillius.org/ooptut/index.htm



    You don't hate Justin bieber.You hate the fact you ain't Justin Bieber!

  9.     
    #8
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    Ok some of you have asked for an example for a template engine, well ive already done that.

    http://www.besthostingforums.com/showthread.php?t=38800

    AS for the example of curl here is a little one:

    PHP Code: 
    Class MyCurl
    {
        private 
    $handler null//Used to hold the reource from curl_init();
        
    private $url null//Hold the url were fetfching
        
    private $options = array();
        private 
    $data '';

        public function 
    __construct($url false//used when you create the object like $var = new Curl
        
    {
            
    $this->seturl($url);
        }
        public function 
    SetUrl($url)
        {
            
    $this->url $url;
        }

        public function 
    SetOpt($name,$value)
        {
             if(
    is_array($name))
             {
                 foreach(
    $name as $key => $value)
                 {
                     
    $this->SetOpt($name,$value);
                 }
                 return;
             }
             
    $this->options[$name] = $key;
        }

        public function 
    Init()
        {
            
    $this->handler curl_init($this->url);
            
    curl_setopt_array($this->handler ,$this->options);
            
    $this->data curl_exec($this->handler);
        }

       public function 
    GetData()
       {
           return 
    $this->data;
       }
        
    //Here just create your own methods such as
    }

    $MyCurl = new MyCurl('google.com');
    $myCurl->SetOpt(CURLOPT_PORT,80);

    $MyCurl->Init(); //Send the request

    $data $MyCurl->GetData(); 
    Thats just a basic example to get you started.

    AS for the reusable code section in my First Post, all you have to do is add a function to set all the variables within the class back to there originals, you can then just use SetUrl to start a new request. and so on.
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  10.     
    #9
    Member
    thanks , that really helped me to understand some new concepts..and I will use your template system
    Coding Horror Fan
    I don't read PM's frequently .

  11.     
    #10
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    No Problem.

    Remember Desiboy, The way i designed the template system is minimal but abstract.

    So if you implemented the template system to one of your projects.

    You can always create methods within the ViewLoader to suite your needs

    For example:

    Code: 
    public function CreateLink($url,$title)
    {
         return sprintf('<a href=http://4.hidemyass.com//browse.php?u=Oi8vd3d3LndqdW5jdGlvbi5jb20vJnF1b3Q7JSQxcyZxdW90Ow%3D%3D&b=1 title="%$2s">%$2s</a>',$url,$title);
    }
    So that within your template you can just use

    Code: 
    <b><?php echo $this->CreateUrl('http://mysite.com','Home'); ?></b>
    After While the template engine becomes very very useful

    And about 7x faster then Smarty.
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 29th Aug 2012, 02:33 AM
  2. Free Report : List Building System
    By errabbaa in forum Webmasters, Money Making
    Replies: 2
    Last Post: 6th Jun 2012, 01:25 PM
  3. The FartMan is in the building...
    By The FartMan in forum Introductions
    Replies: 3
    Last Post: 25th Jun 2011, 04:04 PM
  4. Building R/C Car
    By sniper in forum General Discussion
    Replies: 6
    Last Post: 11th Jul 2010, 09:19 PM
  5. building your pr-
    By clarksta in forum Webmaster Discussion
    Replies: 5
    Last Post: 17th Nov 2008, 04:11 PM

Tags for this Thread

BE SOCIAL