0

Please review the below code and advise what is wrong with it when using require.

First here is the code that works (not using require in it):

<?php //require("_start.inc"); session_start(); if(!isset($_SESSION['user'])) { echo "<h1 style='color:red'>Please <a href='../index.php'>login</a> first!</h1>"; } else { ?> <!DOCTYPE html> <html> <head> <title>Main window</title> </head> <body> <h1>Admin panel</h1> <?php require("header.inc"); ?> </body> </html> <?php //require("_end.inc"); } ?> 

And here is the version that doesn't work, _start.inc and _end.inc are exactly what is written in the above code, but the below one give me an error: Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\admin_start.inc on line 9

<?php require("_start.inc"); /*session_start(); if(!isset($_SESSION['user'])) { echo "<h1 style='color:red'>Please <a href='../index.php'>login</a> first!</h1>"; } else { */ ?> <!DOCTYPE html> <html> <head> <title>Main window</title> </head> <body> <h1>Admin panel</h1> <?php require("header.inc"); ?> </body> </html> <?php require("_end.inc"); //} ?> 
1
  • What is this file called - is the one you have presented "admin_start.inc"? Commented Feb 14, 2013 at 23:53

1 Answer 1

1

You cannot have an opening brace in one and the corresponding closing brace in the other file. Includes doesn't work like copy&paste. The files always must still be valid.

Btw: Use an IDE. It will tell you about such errors.

Sign up to request clarification or add additional context in comments.

1 Comment

I see now that include/require doesn't work like copy/paste. But isn't there some language construct that work that way? If there isn't then i will have to plan my code better i suppose. Thanks for the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.