ItsWesYo Posted July 12, 2006 Share Posted July 12, 2006 Recently, I asked my friend if he knew a php code where I could add other pages into the page or whatever. He told me to use elseif and such. Well, I want to have a php script inside it, but it comes up with errors. Here is the whole page code. For the example, I'll use my [b]about.php[/b] code.[code]<?phpinclude ("http://www.evermoreforums.com/wes/header.php");$page = $_REQUEST['page'];if($page == "basics"){echo ( "blah, content goes here" );die();}elseif($page == "likes"){echo ( "blah, other content goes here" );die();}elseif($page == "dislikes"){echo ( "other content goes here, again" );die();}else {echo ( "this is the page that shows up as 'about.php'like, the "main" page ");die();}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/ Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 A better way to do it might be use includes:[code]<?phpinclude ("http://www.evermoreforums.com/wes/header.php");$page = $_REQUEST['page'];if($page == "basics"){include("basics.php");}elseif($page == "likes"){include("likes.php");}else{include("defaultpage.php");[/code]If you do it like this, you can avoid having a massive file. Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56704 Share on other sites More sharing options...
ShogunWarrior Posted July 12, 2006 Share Posted July 12, 2006 Here's it nicely wrapped up. PS, you should include a foreign file "http:// etc.." many PHP systems will have it blocked anyway. You should include it locally like [b]include("/wes/header.php");[/b]Here's the code:[code]<?phpinclude ("http://www.evermoreforums.com/wes/header.php");$page = ((isset($_REQUEST['page']))?($_REQUEST['page']):(''));switch($page){ case "basics": { echo ( "blah, content goes here" ); break; } case "likes": { echo ( "blah, content goes here" ); break; } case "dislikes": { echo ( "blah, content goes here" ); break; } default: { echo ( "this is the page that shows up as 'about.php'like, the main page"); break; }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56706 Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 Ah yes, a switch statement is probably better here...i always seem to forget about those. Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56707 Share on other sites More sharing options...
ItsWesYo Posted July 12, 2006 Author Share Posted July 12, 2006 So can I use php scripts inside in those pages too? Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56715 Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 Yes, you include a php file. Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-56834 Share on other sites More sharing options...
ItsWesYo Posted July 28, 2006 Author Share Posted July 28, 2006 Sorry for bumping this, but I needed a change of plans for something.For ShogunWarrior's code, how would I include a page in the code? Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-65258 Share on other sites More sharing options...
ShogunWarrior Posted July 28, 2006 Share Posted July 28, 2006 Instead of the [b]echos[/b] e.g: echo('Content');Replace them with an include of another page you have created: [b]include('content.php');[/b] Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-65271 Share on other sites More sharing options...
ItsWesYo Posted July 28, 2006 Author Share Posted July 28, 2006 Ah, thanks once again. Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-65284 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 you can but it's not necessary on includes, without how many you end up using it's easiesinclude 'url';automatically includes, it's faster if you use a lot of includesalso in the url sometimes in php.ini it has a prefix, if so you ALWAYS have to put a ./ in front of the urland ../ if it's 2 levels feep Quote Link to comment https://forums.phpfreaks.com/topic/14374-elseelseif/#findComment-65467 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.