freaka Posted July 24, 2008 Share Posted July 24, 2008 Hey guys, i've had you all help me with this once before, but now im haveing a problem! I would like to be able to have my index.php file include specific content based on what url i type for example: if i type in http://djfreaka.com/cloudnyne/index.php?p=downloads i would like it to include downloads in the content div of my site if i type in http://djfreaka.com/cloudnyne/index.php?p=art i would like it to include art in the content area of my site but when you call on http://djfreaka.com/cloudnyne/index.php without a variable for the get statement, i want it to display the welcome message by default. this is the source for my index.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=utf-8" /> <title>Cloud Nyne Produktions</title> <meta name="description" content="put your site description in here"> <meta name="keywords" content="Use no more than 12 unique search terms separated by a comma and space. "> <meta name="copyright" content="Nokio - 2008"> <meta name="author" content="Nokio/Cloud Nyne Produktion"> <meta name="email" content="your e-mail goes here"> <meta name="Rating" content="General"> <meta name="Robots" content="INDEX,FOLLOW"> <meta name="Revisit-after" content="7 Days"> <style type="text/css"> <!-- body { font: 100% Verdana, Arial, Helvetica, sans-serif; background: #666666; margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */ padding: 0; text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */ color: #000000; background-color: #620000; } .oneColLiqCtrHdr #container { width: 80%; /* this will create a container 80% of the browser width */ background: #000000; margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */ border: 1px solid #000000; text-align: left; /* this overrides the text-align: center on the body element. */ } .oneColLiqCtrHdr #header { background: #000000 ; } .oneColLiqCtrHdr #navigation { background: #990000 url(images/nav-bg.gif) repeat-x; text-decoration:none } .oneColLiqCtrHdr #header h1 { margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */ padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */ } .oneColLiqCtrHdr #mainContent { padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */ background: #000000; } .oneColLiqCtrHdr #footer { padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */ background: #990000 url(images/nav-bg.gif) repeat-x; } .oneColLiqCtrHdr #footer p { margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */ padding: 0px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */ } body,td,th { color: #CC0000; } .style1 {color: #000000} a:link { color: #CC0000; } a:visited { color: #CC0000; } a:hover { color: #000000; text-decoration:blink; background:#cc0000 } a:active { color: #000000; } #navigation a:hover { background: none; } --> </style> <script type="text/javascript"> <!-- function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> </head> <body class="oneColLiqCtrHdr"> <div id="container"> <div id="header"> <div align="center"><img src="images/top.gif" alt="logo image" width="528" height="145" /> </div> <!-- end #header --></div> <div id="navigation"> <!-- start top navigation --> <div align="center"> <a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/home_over.gif',0)"><img src="images/home.gif" alt="Home" name="home" width="59" height="27" hspace="10" border="0" id="home" /></a> <a href="downloads/downloads.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Downloads','','images/downloads_over.gif',0)"><img src="images/downloads.gif" alt="Downloads" name="Downloads" width="135" height="27" hspace="10" border="0" id="Downloads" /></a><a href="servers/servers.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('servers','','images/servers_over.gif',0)"><img src="images/servers.gif" alt="servers" name="servers" width="100" height="27" hspace="10" border="0" id="servers" /></a><a href="tutorials/tutorials.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('tutorials','','images/tutorials_over.gif',0)"><img src="images/tutorials.gif" alt="tutorials" name="tutorials" width="117" height="27" hspace="10" border="0" id="tutorials" /></a><a href="index.php?p=blogs" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('blogs','','images/blogs_over.gif',0)"><img src="images/blogs.gif" alt="blogs" name="blogs" width="63" height="27" hspace="10" border="0" id="blogs" /></a><a href="admins/admins.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('admins','','images/admins_over.gif',0)"><img src="images/admins.gif" alt="admins" name="admins" width="88" height="27" hspace="10" border="0" id="admins" /></a></div> </div> <!-- end #navigation --> <div id="mainContent"> <!-- start main content here --> <?php $p = $_GET['p']; // $p is nothing if(is_empty($p) || strlen($p) < 1){ $p = "home"; } $file = $p.'.html'; if(file_exists($file)){ include "$file"; }else{ include "error.html"; } ?> <!-- end #mainContent --></div> <div id="footer"> <p align="center" class="style1">(c) 2008 Cloud Nyne Produktions - Nokio takes no responsibility for content. Hits: <?php include ("counter.php"); ?></p> <!-- end #footer --></div> <!-- end #container --></div> </body> </html> when i do this however i get two problems: 1: Fatal error: Call to undefined function: is_empty() in /hsphere/local/home/fre4ka/franztarr.com/cloudnyne/index.php on line 134 2: my footer div disappears Please, tell me what I may be doing wrong. It would really help! Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/ Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 I'd use something like this.... <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p'])) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here $p = "home"; } ?> Added a 'possible pages' array, so that people can't stuff anything they like in there. Just a precaution - but probably not needed for what you're looking for. This is untested - im at work! Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598376 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 using your current code, just change it to this.... <?php $p = $_GET['p']; // $p is nothing if(empty($p) || strlen($p) < 1){ $p = "home"; } $file = $p.'.html'; if(file_exists($file)){ include_once "$file"; }else{ include_once "error.html"; } ?> Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598396 Share on other sites More sharing options...
freaka Posted July 24, 2008 Author Share Posted July 24, 2008 Jonnythunder's code worked really well, except for when i dont type a variable, it doesnt automatically include home.html. for reference here's his code <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p'])) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here $p = "home"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598410 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 try... <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p']) && !empty($_GET['p]) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here $p = "home"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598416 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p'])) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here include("home.html"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598421 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 found the problem.... this is better: <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p']) && !empty($_GET['p']) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here $p = "home"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598423 Share on other sites More sharing options...
freaka Posted July 24, 2008 Author Share Posted July 24, 2008 hey master, whats up with all the 's is that needed or should i remove them and use the rest of the code? Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598434 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 Are you saying that this didn't work.... <?php // Define possible pages that can be called $possible_pages = array("page1", "page2", "page3"); if (isset($_GET['p'])) { $p = $_GET['p']; // Check if the file exists and is in the allowed pages array if (file_exists("$p.html") && in_array($p, $possible_pages)) { include("$p.html"); } else { include("error.html"); } } else { // P is not set. Do default here include("home.html"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598438 Share on other sites More sharing options...
MasterACE14 Posted July 24, 2008 Share Posted July 24, 2008 yeah remove em, I'm not sure why that happens, I think its something to do with Firefox 3 beta lol. When I edit my post it adds all the crazyness. Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598439 Share on other sites More sharing options...
freaka Posted July 24, 2008 Author Share Posted July 24, 2008 JonnyThunder: I placed last version of the code in the file and it works wonderfully! Thanks a million to all of you for your input. Quote Link to comment https://forums.phpfreaks.com/topic/116368-help-with-redirection-script/#findComment-598484 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.