PGTibs Posted January 9, 2009 Share Posted January 9, 2009 I currently have a webpage that includes the content from another page using the <?php include("uploader.php"); ?> command. How can i make it so that when i click on a link that include bit either changes to another page or the include part is over writen with another bit of coding? Thanks. Just ask if you want more of the webpage. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 9, 2009 Share Posted January 9, 2009 it's not that simple. are you trying to change the content without refreshing the page? if so, you need to incorporate some javascript. the easy way is to make one giant webpage, with a DIV for each piece of content. then hide each div except for the first. then add use events to change which div is showing. the other option is to use ajax to dynamically load content into the 'content' div. can you elaborate more on what you are trying to accomplish exactly? then i can probably provide a more definitive answer Quote Link to comment Share on other sites More sharing options...
.josh Posted January 9, 2009 Share Posted January 9, 2009 if you don't mind a full page reload, you can do something like this: <a href='?page=foo'>foo page link</a> <a href='?page=bar'>bar page link</a> <?php $allowed = array('foo','bar'); $page = (in_array($_GET['page'],$allowed))? $_GET['page'] : 'defaultpagename'; include("{$page}.php"); ?> Quote Link to comment Share on other sites More sharing options...
Brian W Posted January 9, 2009 Share Posted January 9, 2009 If you are talking w/out refreshing the entire page, use AJAX. Other wise, make the include page dynamic: <?php if(isset($_GET['Page'])){ $Page = "\\".$_GET['Page']; $Path = pathinfo($Page); $dirs = array("\\", "\\media"); //Okay directories to grab from //die($Path['dirname']); //for testing reasons if(!in_array($Path['dirname'], $dirs)){ die("Bad directory"); } //Validate directory $Page = ltrim($Page, "\\"); if(is_file($Page)){ //Validating the file exists include($Page); } else { die("Bad file input"); } } ?> This is like Crayon Violent's, but you only need an array of directories, not an array of pages. Depending on your needs, his may be preferable. Quote Link to comment Share on other sites More sharing options...
PGTibs Posted January 9, 2009 Author Share Posted January 9, 2009 if you don't mind a full page reload, you can do something like this: <a href='?page=foo'>foo page link</a> <a href='?page=bar'>bar page link</a> <?php $allowed = array('foo','bar'); $page = (in_array($_GET['page'],$allowed))? $_GET['page'] : 'defaultpagename'; include("{$page}.php"); ?> Thanks for the help, i'll probably use this method, but since i'm not the most advanced in php i might have to ask again about that. However i don't quite understand the above quote. Could you explain how it works and what each part does? Thanks -feels dumb- can you elaborate more on what you are trying to accomplish exactly? Well basically at this moment in time theres an uploading section which is fairly large which is why its included in another file to save me time. And i want to have tabs to change this part but without having to use any iframes. So it could change to another script or page. That any more help? Quote Link to comment Share on other sites More sharing options...
PGTibs Posted January 9, 2009 Author Share Posted January 9, 2009 Managed to work it out. Many thanks, your a big help. Quote Link to comment Share on other sites More sharing options...
.josh Posted January 9, 2009 Share Posted January 9, 2009 // regular html links, except that you are passing a variable/value through the url // via the GET method. format is something.php?variable=value <a href='?page=foo'>foo page link</a> <a href='?page=bar'>bar page link</a> <?php // Since someone can type in the url bar something.php?page=whateverhewants // you want to make sure you only accept allowed values. So, we setup an array // of allowed page names, so in this example, the allowed page names are // foo and bar. $allowed = array('foo','bar'); // now we assign something to $page, using a ternary operator. It's just a // shorthand version of if (condition) { // do something } else { // do something else } // (condition)? true : false; // our condition is to check if the value passed in the url is in the array of allowed // page names. If it is, we assign the GET variable to $page. If it's not, we assign // a default page (like a home or index page, or whatever). $page = (in_array($_GET['page'],$allowed))? $_GET['page'] : 'defaultpagename'; // finally, we include the page include("{$page}.php"); ?> Quote Link to comment 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.