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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include PHP Content

    Hello

    I wonder how can i use the link like this:
    index.php?site=home f.eks

    I have no idea how i can do that.

    I have tried this code but it only shows 1 file even if i change the url
    PHP Code:
    <?php
    if(!isset($site)) $site="news";
    $invalide = array('\\','/','//',':','.');
    $site str_replace($invalide,' ',$site);
    if(!
    file_exists($site.".php")) $site "news";
    include(
    $site.".php");
    ?>

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    12
    Thanks
    0
    Thanked 1 Time in 1 Post
    it's possible that register_globals is off, which means that $site is never set, and in your code that means it would always default to news. Try using $_GET['site'] instead.

    Also, you have to be really careful when including files based on the GET parameters. I would create an array of valid "sites" and check the GET parameter against them, as shown below. Note that you'll have to add all the valid possible values for $site to the $valid_sites array.

    PHP Code:
    <?php

    $valid_sites 
    = array( 'news''home''etc' );
    $site 'news'//default

    //
    // check to see if $_GET['site'] is set AND that
    // the given site exists in our $valid_sites array
    //
    if ( isset($_GET['site']) && in_array($_GET['site'], $valid_sites) ) {
      
    $site $_GET['site'];
    }

    //
    // Just an extra security precaution. basename()
    // will strip out any path information and return only a 
    // filename
    //
    $site basename($site);

    if ( !
    file_exists($site '.php') ) {
      
    $site 'news';
    }

    require_once(
    $site ".php" );
    ?>
    Last edited by jim_keller; 11-27-2010 at 05:49 PM.

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Thanks alot


  •  

    Posting Permissions

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