mynamesleo Posted October 24, 2006 Share Posted October 24, 2006 Hi all ;) I am new to the forum, googled php help and was located here!I am a complete beginner in PHP, I know some basic [i]html[/i] though.[b]Question[/b]On my site I want it to load a page within a page, so I can keep the logo and "naviation" links at the top without having to have that code in every page on the site. A guy a while back did this for me bud sadly my FTP got wiped and I lost all the files. I remember it was something like; site.com/?p=home, site.com/?p=contact, etc.. etc...Hope this is enough information for you to know what I meanThanks in advance Quote Link to comment Share on other sites More sharing options...
trq Posted October 24, 2006 Share Posted October 24, 2006 Of course there are many ways to do this, a simple example though. Call this index.php. then name all your other file contact.php, home.php etc etc...[code=php:0]// put your header code here.<?phpif (isset($_GET['p'])) { $file = $_GET['p'].'php'; if (file_exists($file)) { include $file; }}?>// put your footer code here.[/code]Simply call your site via http://yoursite/index.php?p=home Quote Link to comment Share on other sites More sharing options...
mynamesleo Posted October 26, 2006 Author Share Posted October 26, 2006 Thanks that works perfect Quote Link to comment Share on other sites More sharing options...
mynamesleo Posted October 27, 2006 Author Share Posted October 27, 2006 Actually I had to edit it on this line: [code]$file = $_GET['p'].'php';[/code]Had to add a . in 'php'[code]$file = $_GET['p'].'.php';[/code]Ok now I wanted it to default to home.php whenever the site is visited (site.com) instead of index, I got this so far:[code]<?phpif (isset($_GET['p'])) { $file = $_GET['p'].'.php';} else { include "home.php";}if (file_exists($file)) { include $file; }?>[/code]It seems to work, but is the code OK? I am just starting out in php but program in Visual Basic ::) Quote Link to comment Share on other sites More sharing options...
Barand Posted October 27, 2006 Share Posted October 27, 2006 I think the logic would be clearer if it were written as[code]<?phpif (isset($_GET['p'])) { $file = $_GET['p'].'.php'; if (file_exists($file)) { include $file; }} else { include "home.php";}?>[/code] Quote Link to comment 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.