Jump to content

Change include ($info) to different value when clicking link


king.oslo

Recommended Posts

Hello,

 

I am trying to learn php, and I am practising sessions.

 

I want to use index.php as the only file which I would like to open in the browser. I am using include ($info) and include ('menu.inc.php') to add contents.

 

I am stuck though. Can I use a link which will reload:

 

$_SERVER['PHP_SELF'] . "?" . SID;

 

...and then somehow update $info with a new filename associated with the link, so that that include($info) reloads index.php but with new contents?

 

How would I do that?

 

Thanks! :)

 

Marius

Try this King.

 

Contents of "a.php":

 

Hello, this message is being served from a.php!<br/>

 

Contents of "b.php":

 

Hello, this message here is from b.php!<br/>

 

Contents of index.php

 

<?php

echo("This will always be at the top.<br/>");

//# This will dynamically include the file in the querystring "page". Example index.php?page=a or ?page=b
include($_GET['page'].".php");

echo("This will always be at the bottom.<br/>");
?>

Try this King.

 

Contents of "a.php":

 

Hello, this message is being served from a.php!<br/>

 

Contents of "b.php":

 

Hello, this message here is from b.php!<br/>

 

Contents of index.php

 

<?php

echo("This will always be at the top.<br/>");

//# This will dynamically include the file in the querystring "page". Example index.php?page=a or ?page=b
include($_GET['page'].".php");

echo("This will always be at the bottom.<br/>");
?>

 

Just make your default landing page like this:

<?php

$page = $_GET['page'];
if($page == 'a'){
  $view = 'a.php';
}elseif($page == 'b'){
  $view = 'b.php';
}else{
  $view = 'default.php';
}

echo("This will always be at the top.<br/>");

//# This will dynamically include the file in the querystring "page". Example index.php?page=a or ?page=b and now it won't be hackable
include($view);

echo("This will always be at the bottom.<br/>");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.