You are here:

PHP5/Parse error

Advertisement


Question
Hello Kevin

Sorry to bother you again, but I'm getting an error related to your code:

-----------------------
<?php  
/**BOOTSTRAPPING**/

include("templates/creation2.5/css/js");
// Set the default name
$action = 'index';
// specify some disallowed paths
$disallowed_paths = array('header', 'footer');
if (!empty($_GET['action'])) {
$tmp_action = basename($_GET['action']);
// If it's not a disallowed path, and if the file exists, update $action
if (!in_array($tmp_action, $disallowed_paths) && file_exists("templates/{$tmp_action}.php))
 $action = $tmp_action;
}
// Include $action
include("templates/$action.php"); //Again here, changing the file extension to allow execution
--------------------------

The error states this when I'm trying to access the root domain (http://www.mydomain.com) as I have index.php set as the default document to load which contains the php code you provided. Any ideas why its have a fit over it? I moved the "//Again here..." down below as well and also left it on the same line.

ERROR:
Parse error: syntax error, unexpected T_STRING in C:\inetpub\wwwroot\index.php on line 15


Thanks again Kevin!
Destry

Answer
Your error is right here:

if (!in_array($tmp_action, $disallowed_paths) && file_exists("templates/{$tmp_action}.php))

If you look closely, you'll see that you're missing your second set of quotes after {$tmp_action}.php

Happy easter!

PHP5

All Answers


Answers by Expert:


Ask Experts

Volunteer


Kevin Cackler

Expertise

Any and everything related to PHP4 and PHP5. I specialize in functional, readable, scalable object oriented code, and can answer your troublesome class and object questions.

Experience

5 years developing in PHP using flat files and databases (MySQL, Oracle) Lead PHP developer for a very large Texas based web hosting company The coder behind some of the largest pet communities online.

Education/Credentials
BS - IT/CS

©2016 About.com. All rights reserved.