Zolomon Posted January 5, 2008 Share Posted January 5, 2008 Hello! I am new to this forum, and I tried to search for my question but I didn't find anything so I decided to ask: EDIT: I did a few more searches and now I found some potential examples. I would still like your help though! I have three sites: index.php <- main site links.php <- site with 5 different links home.php <- site with contents for home portfolio.php <- site with contents for portfolio Question: When you first start index.php, links.php and home.php are included. I wonder how would I, in PHP, be able to include the correct site, for the content for each link that has been pressed? Example: Index.php - Link 1, Link 2, ink 3, ink 4, ink 5, Home content( Welcome to my site etc..!) Press Link 1 and reload index.php with the links.php included as well as portfolio.php (or some other site). Press Link 2 and reload index.php with the links.php included as well as guestbook.php (or some other site). ########### I could use an iframe instead, but I wish to learn how to do this in PHP. Please, help me! Cheers, Zolomon Quote Link to comment https://forums.phpfreaks.com/topic/84607-solved-php-include/ Share on other sites More sharing options...
corillo181 Posted January 5, 2008 Share Posted January 5, 2008 what you will need to do is use if statment if($_GET['home']){ include "home.php"; }else if($_GET['portfolio']){ include "portfolio.php"; }else if($_GET['other']){ include "other.php"; } Quote Link to comment https://forums.phpfreaks.com/topic/84607-solved-php-include/#findComment-431134 Share on other sites More sharing options...
Zolomon Posted January 5, 2008 Author Share Posted January 5, 2008 Hello! Thank you for your help, very appreciated. This is what I have tried so far, without success: On index.php: <?php $link = isset($_GET['link']) ? $_GET[['link'] : 'home'; include("{$link}.php"); ?> and then this on links.php: <?php echo '<a href="index.php?link=home"><span>Home</span></a>'; echo '<a href="index.php?link=links"><span>Links</span></a>'; echo '<a href="index.php?link=about"><span>About</span></a>'; echo '<a href="index.php?link=guestbook"><span>Guestbook</span></a>'; echo '<a href="index.php?link=portfolio"><span>Portfolio</span></a>'; echo '<a href="index.html?link=link4" id="last"><span>Link 4</span></a>'; ?> but it does not seem to work. I tried to use your if/else statement but that did not work either. Cheers, Zolomon Quote Link to comment https://forums.phpfreaks.com/topic/84607-solved-php-include/#findComment-431159 Share on other sites More sharing options...
Zolomon Posted January 5, 2008 Author Share Posted January 5, 2008 Managed to solve it with: index.php <?php $pages = array('home', 'links', 'about', 'guestbook', 'portfolio', 'link4'); if (isset($_REQUEST['link']) && in_array($_REQUEST['link'], $pages)) { $include = $_REQUEST['link']; } else { $include = 'home'; } include('content/'.$include .'.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/84607-solved-php-include/#findComment-431228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.