You can actually just do this:
PHP Code:
<?php
include('./path/to/file/'.$_GET['var']);
?>
The . concatenates or merges string, whereas the + preforms the mathematical function of addition.
Code:
"string"+"String" == 0
"String"."String" == "StringString"
And, since the order of functions goes from inside parenthesis to outside, the string in concatenated before the value goes to the include function.
The problem with this code:
Code:
$var="dir/"$_GET['page']".inc.php";
Is that it is missing the concatenation. It should be: (Notice the red dots)
Code:
$var="dir/".$_GET['page'].".inc.php";
Security should be taken into account, however, on what files can actually be included since you are using the $_GET super global, which any user can edit. Thus, the user can include whatever file they want. Probably a bad idea.
I hope that answers your questions.
Bookmarks