MadnessRed Posted April 21, 2008 Share Posted April 21, 2008 OK, heres my code. <?php if ($_GET["page"]="home") { include 'index.php'; } elseif ($_GET["page"]="about") { include 'pages/about.php'; } elseif ($_GET["page"]="contact") { include 'pages/contact.php'; } elseif ($_GET["page"]="links") { include 'pages/links.php'; } elseif ($_GET["page"]="games") { include 'pages/games.php'; } elseif ($_GET["page"]="mm2") { include 'pages/mm2.php'; } elseif ($_GET["page"]="mm2cars") { include 'pages/mm2_cars.php'; } elseif ($_GET["page"]="mm2tracks") { include 'pages/mm2_maps.php'; } elseif ($_GET["page"]="mm2mods") { include 'pages/mm2_mods.php'; } elseif ($_GET["page"]="mm2invert") { include 'pages/mm2_invert.php'; } elseif ($_GET["page"]="portal") { include 'pages/portal.php'; } elseif ($_GET["page"]="prospero") { include 'pages/propsero.php'; } elseif ($_GET["page"]="worms") { include 'pages/worms.php'; } elseif ($_GET["page"]="trackmania") { include 'pages/tm.php'; } elseif ($_GET["page"]="computer") { include 'pages/computer.php'; } else { include '404.php'; } ?> so in theory shouldnt this link <a href="http://madnessred.co.cc/page.php?page=about" target="_new">About</a> show pages/about.php? link is below. About Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 change = to == this might work Quote Link to comment Share on other sites More sharing options...
papaface Posted April 21, 2008 Share Posted April 21, 2008 Also this is a better way to do it: <?php switch ($_GET["page"]) { case "home": include 'index.php'; break; case "about": include 'pages/about.php'; break; case "contact": include 'pages/contact.php'; break; case "links": include 'pages/links.php'; break; case "games": include 'pages/games.php'; break; case "mm2": include 'pages/mm2.php'; break; case "mm2cars": include 'pages/mm2_cars.php'; break; case "mm2tracks": include 'pages/mm2_maps.php'; break; case "mm2mods": include 'pages/mm2_mods.php'; break; case "mm2invert": include 'pages/mm2_invert.php'; break; case "portal": include 'pages/portal.php'; break; case "prospero": include 'pages/propsero.php'; break; case "worms": include 'pages/worms.php'; break; case "trackmania": include 'pages/tm.php'; break; case "computer": include 'pages/computer.php'; break; default: include '404.php'; } ?> Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted April 21, 2008 Author Share Posted April 21, 2008 neither worked, get error message Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Warning: include() [function.include]: Failed opening 'pages/about.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 21, 2008 Share Posted April 21, 2008 <?php $page = $_GET["page"]; if (!$page) { include "/home.php"; // default page } else if($page=="home") { include "/pages/home.php"; } // index.php?page=home else if($page=="about") { include "/pages/about.php"; } // index.php?page=about else if($page=="contact") { include "/pages/contact.php"; } // index.php?page=contact else if($page=="links") { include "/pages/links.php"; } // index.php?page=links else if($page=="games") { include "/pages/games.php"; } // index.php?page=games else if($page=="mm2") { include "/pages/mm2.php"; } // index.php?page=mm2 else if($page=="mm2cars") { include "/pages/mm2cars.php"; } // index.php?page=mm2cars else if($page=="mm2tracks") { include "/pages/mm2tracks.php"; } // index.php?page=mm2tracks else if($page=="mm2invert") { include "/pages/mm2invert.php"; } // index.php?page=mm2invert else if($page=="portal") { include "/pages/portal.php"; } // index.php?page=portal else if($page=="prospero") { include "/pages/prospero.php"; } // index.php?page=prospero else if($page=="mm2cars") { include "/pages/mm2cars.php"; } // index.php?page=mm2cars else if($page=="worms") { include "/pages/worms.php"; } // index.php?page=worms else if($page=="trackmania") { include "/pages/trackmania.php"; } // index.php?page=trackmania else if($page=="computer") { include "/pages/computer.php"; } // index.php?page=computer else { echo "<b><h1>404 Error</h1></b>"; } // error message ?> You're welcome. Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted April 21, 2008 Share Posted April 21, 2008 wheres it getting the data from?? Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted April 21, 2008 Author Share Posted April 21, 2008 <a href="http://madnessred.co.cc/page.php?page=about" target="_new">About</a> Quote Link to comment Share on other sites More sharing options...
dezkit Posted April 21, 2008 Share Posted April 21, 2008 post the whole code, or just line 10. Quote Link to comment Share on other sites More sharing options...
papaface Posted April 21, 2008 Share Posted April 21, 2008 neither worked, get error message Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Warning: include(pages/about.php) [function.include]: failed to open stream: No such file or directory in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Warning: include() [function.include]: Failed opening 'pages/about.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/grewa/public_html/beltd.co.uk/page.php on line 10 Those errors have nothing to do with the code itself, you've got your paths wrong. My code works fine and is actually MUCH better than your if...elseif approach. Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted April 21, 2008 Author Share Posted April 21, 2008 ok, then here is my directory structure index.php page.php >pages ...about.php ...contact.php ...ect ect any idea why it doesn't work? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 21, 2008 Share Posted April 21, 2008 Try ./pages/page_name.php rather than pages/page_name.php Make sure the pages folder is in the same folder as pages.php Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted April 21, 2008 Author Share Posted April 21, 2008 thanks wild teen, that fixed it Quote Link to comment Share on other sites More sharing options...
MadnessRed Posted April 21, 2008 Author Share Posted April 21, 2008 and thankyou to everyone who helped. 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.