Jump to content

[SOLVED] php includes with unbalanced braces


poleposters

Recommended Posts

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?

 

 

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'); 
?>

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.