Results 1 to 6 of 6

Thread: How To Use include Function Safely ?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    How To Use include Function Safely ?

    hi ,
    How do you use include function safely to avoid anything relation about Injection....
    & To design Your page do You use different page ?
    i mean do you use single page That containe The header & the menu .. ?
    or do you use different & you call in index.php using include function

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How To Use include Function Safely ?

    The safe way to include the script is to hard code the name of it in your including script. This way, if the user tries to inject data or point it to a URL; it will be ignored and an error page displayed.

    Also, disable URL fopens too. You should NEVER need it.
    PHP Code:
    $location $_GET['location'];
    $include '';

    switch (
    $location) {
        case 
    'home':
            
    $include 'contact.php';

        case 
    'contact':
            
    $include 'contact.php';

        case 
    'admin':
            
    $include 'admin.php';

        default: 
    // anything else the user entered
            
    $include 'error.php';
    }

    include 
    $include
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: How To Use include Function Safely ?

    Thanks m8
    what about To design Your page do You use different page ?
    i mean do you use single page That containe The header & the menu .. ?
    or do you use different & you call in index.php using include function

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How To Use include Function Safely ?

    No - there is no reason why the same code cannot on separate pages you have require (it's like include). It is best to separate each logical function of the site into separate pages; just as you separate each entity in a relational database into a table.

    It will also make your site more search engine friendly as it will not see the query string (more likely to be dynamc data and will more likely follow it and crawl the page).
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: How To Use include Function Safely ?

    Yes Better Thanks !

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: How To Use include Function Safely ?

    A typical set of pages may look like this:
    Code:
    -- include
        -- site.php
        -- auth.php
    -- htdocs
        -- login.php
        -- login_input.php
        -- cart.php
        -- cart_input.php
        -- index.php
        -- contact.php
        -- contact_input.php
    The site.php could be included and used to check authentication tokens and set up the / retrive the current state.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

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



Click Here to Expand Forum to Full Width