Jump to content

Include File Issue


son

Recommended Posts

When I put the following script fully into php include file I will only see an empty page when opening page in browser:

if (!isset($_SESSION['name'])) {// start defining the URL$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);// check for a trailing slashif ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {$url = substr ($url, 0, -1); // chop off the slash}// add the page$url .= '/index.php';ob_end_clean(); // delete the bufferheader("Location: $url");exit(); // quit the script} else {

Removing the top and bottom line and having the relevant line in the php file that includes the file as:

if (!isset($_SESSION['name'])) {include_once('inc/session.php');} else {

it works (I see the page with all elements in it). Why can I not putif (!isset($_SESSION['name'])) {and } else {also in include file? Do not understand...Son

Link to comment
Share on other sites

Include files need to be syntactically correct, you can't have an if/else statement that doesn't end. It's going to check the syntax of the file before it includes it.
Now I understand. I can only have complete if/else statements in include files. If this is not possible for the complete script that is common to several files I only put the bit that is complete as such...Many thanks,Son
Link to comment
Share on other sites

When you include, doesn't it automatically escape from php mode and return after the include? I'd have thought you'd need the openong and closing php tags

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...