irkevin Posted October 23, 2007 Share Posted October 23, 2007 Hi, i want to do something but i don't really know how to achieve this I have index.php and all want all page to display on index.php.. Supposed i have home | music | stuffs | aboutus i would like it to display on index.php. Just like the url would be index.php?page=home index.php?page=music index.php?page=stuffs index.php?page=aboutus I know that switch , case and break have something to do with it but know how to apply it ! Can someone give me a brief example please? Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/ Share on other sites More sharing options...
irkevin Posted October 23, 2007 Author Share Posted October 23, 2007 Oops No one :'( Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-375984 Share on other sites More sharing options...
chanchelkumar Posted October 23, 2007 Share Posted October 23, 2007 just include one page for this .. and do it with a if condition... it will be more easier for you.... i have one example with me... and i think it will be more difficult to you to understand... if you really want it i will send it to you..... Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-375988 Share on other sites More sharing options...
wildteen88 Posted October 23, 2007 Share Posted October 23, 2007 You'll want to use $_GET['page'] to grab the page url variable. You'll then want to setup an array of all the pages visitors are allowed access to, eg $my_pages = array('home', 'music', 'stuffs', 'aboutus'); Then you'd use in_array function within an if statement to check if the value of $_GET['page'] is stored in the $my_pages array. If its you'd then use $_GET['page'] in an include. Example code: // check that $_GET['page'] is present, if its not we'll setup a default page if(isset($_GET['page'])) && !empty($_GET['page'])) { $requested_page = strtolower($_GET['page']); } else // $_GET['page'] not found or is empty, so we'll setup a default page to be requested { $requested_page = 'home'; } // setup an array of all your sites pages $my_pages = array('home', 'music', 'stuffs', 'aboutus'); $requested_page = strtolower($_GET['page']); // make sue the request page is in $my_Pages array if(in_array($requested_page, $my_pages)) { // the requested page will be included from a folder called my_pages in your websites root folder. // I assume the files to be included are html files include $_SERVER['DOCUMENT_ROOT'] . '/my_pages/' . $requested_page . 'html'; } else { // requested_page not found die( 'The requested page (' . $requested_page ') was not found!' ); } Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376323 Share on other sites More sharing options...
irkevin Posted October 23, 2007 Author Share Posted October 23, 2007 wouldn't this work also? it's an example i found on this forum <a href="?page='one'>LINK ONE</a> <a href="?page='two'>LINK TWO</a> <a href="?page='three'>LINK THREE</a> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'one': echo "this is one"; break; case 'two': echo "this is two"; break; case 'three': echo "this is three"; break; } } ?> Hoe do i make it dispkay the homepage as a default! See what i mean? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376618 Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 You said it yourself switch($this){ case 'this' echo "this"; break; default: echo "OPO!PO"; } Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376619 Share on other sites More sharing options...
irkevin Posted October 23, 2007 Author Share Posted October 23, 2007 Which mean it could be like this <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'one': echo "this is one"; break; case 'two': echo "this is two"; break; case 'three': echo "this is three"; break; default: echo "the code for the homepage goes there???"; } } ?> Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376639 Share on other sites More sharing options...
marcus Posted October 23, 2007 Share Posted October 23, 2007 yesm. Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376641 Share on other sites More sharing options...
irkevin Posted October 24, 2007 Author Share Posted October 24, 2007 i have those codes <a href="indexa.php?">Home</a> <a href="indexa.php?page=add">Add Anime</a> <a href="indexa.php?page=edit">Edit Anime</a> <?php $page = $_GET['page']; if (isset($page)) { switch ($page) { case 'add': echo "Testing the add page"; break; case 'edit': echo "Testing the edit page"; break; default: echo "This is the home page where you'll have info"; } } ?> I want to have the indexa.php page to be the default page and show this message "This is the home page where you'll have info" How do i do that? thanks Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376750 Share on other sites More sharing options...
irkevin Posted October 24, 2007 Author Share Posted October 24, 2007 No one? ??? Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376756 Share on other sites More sharing options...
irkevin Posted October 24, 2007 Author Share Posted October 24, 2007 Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376771 Share on other sites More sharing options...
trq Posted October 24, 2007 Share Posted October 24, 2007 <a href="indexa.php?">Home</a> <a href="indexa.php?page=add">Add Anime</a> <a href="indexa.php?page=edit">Edit Anime</a> <?php if (isset($_GET['page'])) { switch ($_GET['page']) { case 'add': echo "Testing the add page"; break; case 'edit': echo "Testing the edit page"; break; default: echo "This is the home page where you'll have info"; } } else { echo "This is the home page where you'll have info"; } ?> Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376773 Share on other sites More sharing options...
jbingman Posted October 24, 2007 Share Posted October 24, 2007 or what i did is just use the if statement without the switch statements so... <? if($_GET['page']==home){ //home page code goes here } if($_GET['page']==music){ //music page code goes here } if($_GET['page']==stuffs){ //stuffs page code goes here } if($_GET['page']==aboutus){ //about us page info goes here } ?> Link to comment https://forums.phpfreaks.com/topic/74412-getting-other-page-to-display-on-indexphp/#findComment-376782 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.