king.oslo Posted June 7, 2009 Share Posted June 7, 2009 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 Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/ Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 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/>"); ?> Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850848 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 That is hackable. Someone can upload a file to the site and run it with that. Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850852 Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 Nothing is foolproof, I was just giving him a concept to run with. Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850853 Share on other sites More sharing options...
alco19357 Posted June 7, 2009 Share Posted June 7, 2009 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/>"); ?> Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850860 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 That is better. I would change a long if, else if to a switch. Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850864 Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 Yeah switch would be better, I agree. Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850866 Share on other sites More sharing options...
alco19357 Posted June 7, 2009 Share Posted June 7, 2009 That is better. I would change a long if, else if to a switch. ditto. wasn't thinking that while i was doing it. but yes Link to comment https://forums.phpfreaks.com/topic/161235-change-include-info-to-different-value-when-clicking-link/#findComment-850882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.