cpugeek Posted August 2, 2007 Share Posted August 2, 2007 Okay, so i have this code: <?php $x=basename($_GET['x']); $allow=array('index', 'default', 'pageone', 'pagetwo', 'pagethree'); // Take out whatever files you want, or add more if (file_exists("$x.php") && in_array($x, $allow)) { include("$x.php"); } else { include("default.php"); }?> & it works but i was wondering if there is a way i could do it without an array.Or if i could include the array.Any & All help is appreciated Link to comment Share on other sites More sharing options...
justsomeguy Posted August 2, 2007 Share Posted August 2, 2007 An array is the best way to do it, if you want to include all the files in the array then you can just loop through and include each one. Link to comment Share on other sites More sharing options...
cpugeek Posted August 2, 2007 Author Share Posted August 2, 2007 what modifications to my code would i have to make?what wouldx my code look like? Link to comment Share on other sites More sharing options...
cpugeek Posted August 2, 2007 Author Share Posted August 2, 2007 what modifications to my code would i have to make?what would my code look like?because i think you might have misunderstood.what i want is to include my array from an exterior file so that there isn't a long line of files.i was just wondering if i could include the array like a regular file.like so:index.php <?php $x=basename($_GET['x']); include("array.php"); if (file_exists("$x.php") && in_array($x, $allow)) { include("$x.php"); } else { include("default.php"); }?> array.php $allow=array('index', 'default', 'pageone', 'pagetwo', 'pagethree'); // Take out whatever or something like that. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 2, 2007 Share Posted August 2, 2007 Yeah, you can do that. Make sure you have the PHP tags in the included file. Link to comment Share on other sites More sharing options...
cpugeek Posted August 2, 2007 Author Share Posted August 2, 2007 thx.for the quick responsei thought that i could do it that way.but i wasn't sure.thx. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.