1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. To chat with the GameOgre community, you need to have at least 100 posts. Once you have the 100 posts, post at Become A New Ogre
    Dismiss Notice

php include

Discussion in 'Online Game Development' started by shugo, Apr 20, 2012.

Thread Status:
Not open for further replies.
  1. shugo

    shugo Elite Ogre Ogre Veteran

    Messages:
    2,093
    Likes Received:
    12
    Trophy Points:
    38
    Credit:
    15,378.42
    PHP include() and require()

    This neat little function saves me a lot of time.

    In almost every php file in my game I need to check the cookie and I need to establish a connection with sql and I need to select an sql database. Those 3 things alone are about 30 or more lines of code. With include I can put those three things into 1 php file. I can then include this one file into the other files.

    The benefit of this is that if I were to make changes to the sql connection or the cookie, I would have to alter the code in 1 php file, instead of almost every php file. It saves me a lot of time and effort.

    The include itself is 2 lines of code, the include file has 30 lines of code. I'm thus able to shorten most files by 28 lines of code (30 - 2 = 28). This makes the code easier to read in really long files. That's the benefit of an object oriented style of programming versus a procedural style of programming.

    Because no variable is the same in my game code, I almost never have need of objects and user defined functions in php (afterall why repeat something when there is no need). However the connection and cookie is at least one area where object oriented programming is beneficial.


    http://www.w3schools.com/PHP/php_includes.asp
     
  2. shugo

    shugo Elite Ogre Ogre Veteran

    Messages:
    2,093
    Likes Received:
    12
    Trophy Points:
    38
    Credit:
    15,378.42
    If you do use includes, you need to be weary of the possible security issues. Most of the security issues are due to flaws in the code. Includes are prone to injections, just like regular php code with external variables is prone to sql injections.
     
  3. Admin Post
    ogreman

    ogreman Ogre In Charge Staff Member GameOgre Admin

    Messages:
    52,032
    Likes Received:
    8,869
    Trophy Points:
    113
    Credit:
    460,538.39
    Yes, we need something like this for the oldest areas of the site:).
     
Thread Status:
Not open for further replies.

Share This Page