Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on 

How do I include a file that is determined from a function??

Hi, I am trying to dynamically select which blurb to include on the page according to which link was clicked.

include 'header.php';
$blurb = blurbs();
var_dump($blurb);
include $blurb;
include 'footer.php';

Open in new window


But its not working even though 1blurb.php is a an active page:  http://gowiththemaster.com/tleithoff/1blurb.php

http://gowiththemaster.com/tleithoff/about.php?menu=1&type=1blurb

Anyone know how to do this?

// Determines which blurb should be included
function blurbs() {
	if(isset($_GET['type'])) {
		$blurb = $_GET['type'];
		$blurb = "'" . $blurb . ".php'";
		return $blurb;
	}
}

Open in new window

PHP

Avatar of undefined
Last Comment
Zyloch
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of FairyBusiness
FairyBusiness
Flag of United States of America image

ASKER

hmmmm not sure how I would do any input validation.  but thanks it worked!
Avatar of Zyloch
Zyloch
Flag of United States of America image

You can have a list of allowed blurbs somewhere against which you can compare. Or you can parse the query string to remove ../ and only include files in a specific blurb directory.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo