1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

double include()

Discussion in 'PHP' started by sebastya, Oct 6, 2006.

  1. #1
    I know there is a code for this but I can't remember which site it was on.

    An example would be:

    For the "index.php" of my site I want to display "news.txt" in my content area, and my links will be "index.php?id=whatever".

    So if I went to "www.mysite.com" the toolbar would not read or be redirected to "index.php?id=news.txt" but the news would already be there, yet for every other link the URL will change to "index.php?id=page"

    do you know what I mean? sorry If I didn't explain it properly but hopefully someone understood and knows the code for it :)
     
    sebastya, Oct 6, 2006 IP
  2. vdd

    vdd Peon

    Messages:
    34
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hm...
    index.php:
    <?
    ...
    // you must check/filter id, because of include-hack
    include($id);
    ...
    ?>
     
    vdd, Oct 6, 2006 IP
    sebastya likes this.
  3. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #3
    if (isset($_GET['id'])) {
      include($_GET['id']);
    } else {
      include("news.txt");
    }
    PHP:
     
    harsh789, Oct 6, 2006 IP
    sebastya likes this.
  4. yutewa00

    yutewa00 Peon

    Messages:
    245
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    // If 'url' is sent via GET method, include it, else display default index site
    if (isset($HTTP_GET_VARS['url'])) {
    	
    	$include = str_replace('../', '', str_replace('http://', '', $HTTP_GET_VARS['url']));
    
    	while ($include[0] == '/')  {
    		$include = substr($include, 1);
    	}
    if ($include == "index") echo "Not allowed";
    	// .php is added here for safety reasons (link should be without .php)
    	if (file_exists($include.'.php')) {
    		include_once $include.'.php';
    	} else {
    		echo "Can't find the page u r looking for.";
    	}
    } else {
    	// Display default index site
    	include_once "news/news.php";
    	
    }	
    
    
    ?>
    PHP:
    with this you will have links like : index.php?url=page
    also you can add files to folders so the link will be :index.php?url=folder/page
    Change $HTTP_GET_VARS['url'] to GET['url'] if it's not working on your server.
    or just change ['url'] for different ulrs. script includes default file if file user is requesting is not there

    I hope this helps.
     
    yutewa00, Oct 6, 2006 IP
    sebastya likes this.
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    
    //Get page
    $page = strtolower($_GET['id']);
    
    //List of allowed pages
    $page_array = array('index','faq','login','forgotpass','register','account','main','etc');
    
    if(in_array($page,$page_array)){
    include($page.'.php');
    } else {
    include('index.php');
    }
    
    
    PHP:
    Peace,
     
    Barti1987, Oct 6, 2006 IP
    sebastya likes this.
  6. sebastya

    sebastya Well-Known Member

    Messages:
    2,449
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    138
    #6
    Thanks! I tried the other two but it didn't work out. Thanks alot guys. Rep added. :D
     
    sebastya, Oct 6, 2006 IP