poleposters Posted August 8, 2009 Share Posted August 8, 2009 Hi. I'm tidying up some of my scripts. Is it possible to include a php file with unclosed brackets? I went ahead and created two files. header.php and footer.php because my scripts began and ended the same way. header.php <?php require_once($_SERVER['DOCUMENT_ROOT'].'/mysql_connect.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/fckeditor/fckeditor.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/ref.php'); session_start(); if(isset($_SESSION['name'])) { ?> footer.php <?php include("console.inc.php"); } else { header("Location:/admin/login.php?ref=12"); } ?> As you can see the files individually have unbalanced braces. But when they combine at the top and bottom of my script they balance out. Are these includes possible? Quote Link to comment https://forums.phpfreaks.com/topic/169312-solved-php-includes-with-unbalanced-braces/ Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 No this is not possible. You're better of just doing <?php session_start(); if(!isset($_SESSION['name'])) { header("Location:/admin/login.php?ref=12"); exit; } require_once($_SERVER['DOCUMENT_ROOT'].'/mysql_connect.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/fckeditor/fckeditor.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/ref.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169312-solved-php-includes-with-unbalanced-braces/#findComment-893442 Share on other sites More sharing options...
TeNDoLLA Posted August 8, 2009 Share Posted August 8, 2009 I could imagine if you include all the files into one file in correct order it would work. Because isn't include same as the code was written in the file in the spot where the include happens. But I don't think this will be a good way to do anything. Quote Link to comment https://forums.phpfreaks.com/topic/169312-solved-php-includes-with-unbalanced-braces/#findComment-893445 Share on other sites More sharing options...
wildteen88 Posted August 8, 2009 Share Posted August 8, 2009 I could imagine if you include all the files into one file in correct order it would work. Because isn't include same as the code was written in the file in the spot where the include happens. But I don't think this will be a good way to do anything. It wont work as PHP will first evaluates the code. If there are syntax errors it be able to parse the code. Quote Link to comment https://forums.phpfreaks.com/topic/169312-solved-php-includes-with-unbalanced-braces/#findComment-893446 Share on other sites More sharing options...
poleposters Posted August 8, 2009 Author Share Posted August 8, 2009 I can't believe I didn't think of that. I was trying to complicate things. Thank you. Its a very elegant solution. Quote Link to comment https://forums.phpfreaks.com/topic/169312-solved-php-includes-with-unbalanced-braces/#findComment-893451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.