Exact Posted November 30, 2009 Share Posted November 30, 2009 hey guys, when people go to the home page i want it to show a middle file called middle.php, any other page, i want it to not show up. This code doesnt seem to show the middle.php, leaves it out completely: <?php if ($page != 'home' && $page != '') include('middle.php');?> can anyone see anything wrong with the above code? Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/ Share on other sites More sharing options...
trq Posted November 30, 2009 Share Posted November 30, 2009 Your logic seems to be completely around the wrong way. <?php if ($page == 'home') include('middle.php');?> Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967784 Share on other sites More sharing options...
Jnerocorp Posted November 30, 2009 Share Posted November 30, 2009 im not sure but wouldnt it have to be like this? <?php if ($page == 'home') { include('middle.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967788 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 neither of those scripts seem to pull it. would my other code be clashing with it? this script is in another file, but this wouldnt be stopping it would it? <?php $files = glob('*.php'); if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } }} else { include 'home.php'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967792 Share on other sites More sharing options...
Jnerocorp Posted November 30, 2009 Share Posted November 30, 2009 could you pot all of your page's php code -John Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967795 Share on other sites More sharing options...
trq Posted November 30, 2009 Share Posted November 30, 2009 Where is $page defined? Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967797 Share on other sites More sharing options...
mikesta707 Posted November 30, 2009 Share Posted November 30, 2009 <?php $files = glob('*.php'); if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); //include middle if (strtolower($_GET['page']) . ".php" == "home"){ include("middle.php"); } }//end if }//end foreach }//end if else { include 'home.php'; include "middle.php"; } ?> something like that is probably what you want to do Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967802 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 $page isnt defined. where should and how should i add it in? that last post i cant use as i need middle to be up the top and home.php to be down below in a frame. so it screws it up. Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967807 Share on other sites More sharing options...
trq Posted November 30, 2009 Share Posted November 30, 2009 $page isnt defined. where should and how should i add it in? How should we know? maybe you mean to use $_GET['page'] ? Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967811 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 sorry mate a newbie... trying to get my head round it :-\ Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967816 Share on other sites More sharing options...
mikesta707 Posted November 30, 2009 Share Posted November 30, 2009 wouldn't something like <?php if ($page == 'home') include('middle.php');?> work if you change $page to $_GET['page']? $_GET['page'] has the value you want I think Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967819 Share on other sites More sharing options...
corrupshun Posted November 30, 2009 Share Posted November 30, 2009 Is this what your looking for? <?php $page = basename($_SERVER['SCRIPT_NAME']); if($page == index.php) { include('middle.php'); } ?> This reads the page and if the page is index.php it will include middle.php Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967821 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 well that is pretty much wat i wanted but index is on every page. just want it to be on the home page.... tried defining home with that script but cant get it to show when i change it from index. Quote Link to comment https://forums.phpfreaks.com/topic/183352-if-equals-home-show-this-page/#findComment-967830 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.