Jump to content

[SOLVED] Dynamic includes


freelancer

Recommended Posts

Check out this page ( http://www.team-kommando.com/web ), TEAM by navigation and click on Cranx link. See, this file ( cranx.html ) will be included right below the the team.php page, but I want that it would come like all other includes - to clear page - without TEAM page.

 

Here is code I'm useing in index.php:

 

<?php

$pages = array(
                'news'     => 'news/news.php',
                'articles' => 'news/archive.php',
                'team'     => 'team.php',
                'results'  => 'results.html',
                'about'    => 'about.html',
                'servers'  => 'servers.html',
                'sponsors' => 'sponsors.html',
                'contact'  => 'contact.html'
        );
           
             if (isset($_GET['k']) && isset($pages[$_GET['k']]))
                {
                    include($pages[$_GET['k']]);

                    }	else {
                      include($pages['news']);
                }

?>

 

And piece of code in team.php:

<?php

$pages = array(
                'Cranx' => 'team/cranx.html',
                'team' => 'team.php',
        );
           
             if (isset($_GET['id']) && isset($pages[$_GET['id']]))
                {
                    include($pages[$_GET['id']]);

                    }		

?>

 

Please can you tell me how I can fix this and give me some advices please :) Thank you!

Link to comment
https://forums.phpfreaks.com/topic/36665-solved-dynamic-includes/
Share on other sites

You would need to pass on the id in the include.

 

For example:

 

<?php
if(isset($_GET['k']) && isset($pages[$_GET['k']]))
{
if(strcmp($_GET['k'], 'team') == 0)
{
include($pages[$_GET['k']]."?id=".$_GET['id']);
}
else
{
...
}
}
?>

 

At least that's how I'd understand it to work.

Still not working, something is still wrong.

 

Warning: main(team.php?id=) [function.main]: failed to open stream: No such file or directory in /root/web/index.php on line 122

 

Warning: main(team.php?id=) [function.main]: failed to open stream: No such file or directory in /root/web/index.php on line 122

 

Warning: main() [function.include]: Failed opening 'team.php?id=' for inclusion (include_path='.:') in /root/web/index.php on line 122

 

Line 122 is exactly:

 

include($pages[$_GET['k']]."?id=".$_GET['id']);

at my old highschool they use a dynamic include they called it there content box they moved to asp so i snatched there old homepage and tryed to get it working i dont know if it will help but this is the code they used for theirs

 

<?php if (isset($section2) && $section2 != "") 
{ include("/Inetpub/wwwroot/test1".$section2."".$page.".php");} 
else 
{$number = "2"; include 'announcements/show_news.php';} ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.