Jump to content

[SOLVED] Change the content of a page with a click?


PGTibs

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

// 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");
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.