darrennickerson Posted May 16, 2008 Share Posted May 16, 2008 For a thing that seems to be so common in websites i have had alot of trouble in trying to find the code on how to do it. I Have done it before but forget how to do it. www.mysite.com/index.php?page=whatever... I need to have that plus when nothing is after page= have it goto home.html Thanks for your help Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 16, 2008 Share Posted May 16, 2008 depends, but for a simple example, lets assume you have this: index.php header.php navbar.php body.php footer.php and you have these pages you want included in the body: home.html about.html links.html contact.html you would do this in the body.php <?php $good_links = array("home", "about", "links", "contact"); if (isset($_GET['page'])){ if (in_array($_GET['page'], $good_links)){ include($_GET['page'].".html"); } else{ include("home.html"); } } else{ include("home.html"); } ?> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Share Posted May 16, 2008 hey ok i will add little bit more for you ok creat a folder called include... then add in it file you would like to include so main.php forum.php shout.php me.php ect ect then on you index.php or where ever add this <? $page = $_GET['page']; if (ereg('[A-Za-z0-9]',$page) ) { if (file_exists('include/'.$page.'.php')) { include('include/'.$page.'.php'); } else { include('include/main.php'); } } else { include('include/main.php'); }?> so then your link would be www.mysite.com/index.php?page=me bang you have me.php show Quote Link to comment Share on other sites More sharing options...
darrennickerson Posted May 16, 2008 Author Share Posted May 16, 2008 Will that still apply if i dont have everything seperated into body.php nav.php and just have the whole design in the index.php and paste that code into the place where i want the content to go Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 16, 2008 Share Posted May 16, 2008 Will that still apply if i dont have everything seperated into body.php nav.php and just have the whole design in the index.php and paste that code into the place where i want the content to go include() executes the referenced file as if it were part of the script calling include(). Or in other words, when PHP encounters include(), it opens and executes the file and any output from that file gets dumped into the calling script where the include() statement was encountered. So the short answer is, "Yes, that should work." Quote Link to comment Share on other sites More sharing options...
darrennickerson Posted May 16, 2008 Author Share Posted May 16, 2008 it came up with this error {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 HOme\par } � hOme is what i had typed in the home.php file Dont know whats up i appricitate you guys helping and your quick replys Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted May 16, 2008 Share Posted May 16, 2008 Show us your source for index.php and home.html Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 That looks like something Microsoft would do, but I need code to make sure. xD Show us what you have. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 16, 2008 Share Posted May 16, 2008 humm thats wierd lol... have you tried something else in home.php like <?php echo 'home'; ?> Quote Link to comment Share on other sites More sharing options...
darrennickerson Posted May 18, 2008 Author Share Posted May 18, 2008 <html xmlns="http://www.w3.org/1999/xhtml"> <head><script language="JavaScript"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>\</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="content"> <div id="header"> <div id="logo"> <h1>logo here</h1> <h4>have your punchline here</h4> </div> <div id="links"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Projects</a></li> <li><a href="#">Tutorials</a></li> <li><a href="#">Forum</a></li> </ul> </div> </div> <div id="mainimg"> </div> <div id="contentarea"> <div id="leftbar"> <h2>hello!</h2> <? $page = $_GET['page']; if (ereg('[A-Za-z0-9]',$page) ) { if (file_exists('include/'.$page.'.php')) { include('include/'.$page.'.php'); } else { include('include/home.php'); } } else { include('include/home.php'); }?> <br /> </div> <div id="rightbar"> <h2>latest news</h2> <p><span class="orangetext"><?php $tpath = "/home/redneckt/public_html/news/"; $lim = "5"; $page = "/index.php"; include($tpath . "headlines.php"); ?></ span> </p> </div> </div> <div id="bottom"> <div id="email"><a href="mailto:admin@rednecktc.com">Admin@rednecktc.com</a></div> <div id="validtext"> <p>Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a></p> </div> </div> </div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
runnerjp Posted May 18, 2008 Share Posted May 18, 2008 humm and have you mde a folder "include" in the directory and try doing this create a file home.php in it but this <?php echo 'hello world';?> and tell me what ytou get?? Quote Link to comment Share on other sites More sharing options...
darrennickerson Posted May 19, 2008 Author Share Posted May 19, 2008 {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 5.41.15.1512;}\viewkind4\uc1\pard\f0\fs20 hello world\par } � Figured it out for some reason it does that when i use MSword insted of notepad weird 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.