Loryman Posted October 7, 2007 Share Posted October 7, 2007 I'm quite new with PHP, so I'm unsure what do to. But Im guessing what I need is an IF statement, that will display a message saying "The page does not exist" instead of "failed to open stream", for any page that does not exist on the site. This page Can anyone help? Code of index.php is shown below. <center> Displaying page below line: <hr> <?php if(isset($_GET['action'])){ include($_GET['action'].".php"); } else { include("1.php"); } ?> <hr> <a href="index.php?action=1">Display 1.php</a> | <a href="index.php?action=nonexistant">Display Non-Existant Page</a> </center> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/72206-help-with-if-statement/ Share on other sites More sharing options...
chronister Posted October 7, 2007 Share Posted October 7, 2007 passing the page name through the url like that is a little difficult to manage. Are you trying to simply get a 1 layout page template kind of thing going on with it?? If so I can show you a better way. Nate Quote Link to comment https://forums.phpfreaks.com/topic/72206-help-with-if-statement/#findComment-364102 Share on other sites More sharing options...
Loryman Posted October 7, 2007 Author Share Posted October 7, 2007 Yes I am, what way have you got in mind? Quote Link to comment https://forums.phpfreaks.com/topic/72206-help-with-if-statement/#findComment-364104 Share on other sites More sharing options...
chronister Posted October 7, 2007 Share Posted October 7, 2007 hehehe, I came up with a variation of the way your doing it and it became cumbersome. Now I would not develop any other way for 95% of my sites. Ok, most pages have a common area on top, and left with sometimes a right side common as well. But they pretty much all have a single area that the content actually loads in. So here is what I do. Create your main page layout. I will use the standard common head/left nav/footer layout. I use tables, but it can be applied to a css layout in the exact same method. So here is my code for my main page I will call header.php /header.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?=$page_title ?></title> <style type="text/css"> <!-- body { margin: 0px; padding: 0px; } --> </style> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" align="center"><h1>Banner text </h1></td> </tr> <tr> <td width="18%" valign="top"> <a href="#">Link1</a><br /> <a href="#">Link2</a><br /> <a href="#">Link3</a><br /> <a href="#">Link4</a><br /> <a href="#">Link5</a><br /> </td> <td width="82%" align="left" valign="top"> <?php function footer(){ // this is what makes it happen ?> <!--All My Content will load here..--> </td> </tr> <tr> <td colspan="2" align="center"><strong>Footer Text </strong></td> </tr> </table> </body> </html> <?php } //end my footer function ?> I make this my wrapper page. I then define a PHP function called footer() shown in above example. Then on each page I want this to wrap on, I use an include. /page1.php <?php $page_title='Page 1' ; include($_SERVER['DOCUMENT_ROOT'].'/header.php') ?> Here is my page content, make some db calls etc... then I will close the page with a call to the footer function. By calling the include using the doc root superglobal, you can move this page into any directory and it will find the header.php page in the root dir. <?php footer() ?> I do this all the time.... You define the function, then wrap the pages in the include and footer. The page title is defined before the include as it is used in the include. Then creating new pages using it is as easy as this.. /pages/content/testing/page2.php <?php $page_title='Page 2' ; include($_SERVER['DOCUMENT_ROOT'].'/header.php') ?> create content here! <?php footer() ?> Enjoy! Nate Quote Link to comment https://forums.phpfreaks.com/topic/72206-help-with-if-statement/#findComment-364144 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.