unexpected $end

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

unexpected $end

Post by SidewinderX »

ok well i have a bunch of files that i dont want users to be able to access unless the install files are deleted. each file is formated like so:

Code: Select all

<?php
include("header.php");
include("config.php");
//code
//more code
//even MORE code
include("footer.php");
?>
I created a simple script to test to see if the install directory exists:

Code: Select all

<?php
$dir = "install/";
if (is_dir($dir)) {
echo "THE INSTALL DIRECTORY EXISTS, YOU MUST REMOVE IT BEFORE YOU CONTINUE.";
}
else{
echo "THE INSTALL DIRECTORY DOES NOT EXIST";
}
?>
And rather than adding that code to each file, i had planned to add the code to the header and footer. For example header.php would include

Code: Select all

<?php
$dir = "install/";
if (is_dir($dir)) {
echo "THE INSTALL DIRECTORY EXISTS, YOU MUST REMOVE IT BEFORE YOU CONTINUE.";
}
else{
?>
and footer.php would have

Code: Select all

<?php
}
?>
i thought this would work but i get an error
Parse error: syntax error, unexpected $end in c:\www\toplist\header.php on line 7
i assume its because of the open else {

is that infact the reason? if so, is there any easy way of doing what i want rather than adding that code to each file?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes, it is the fault of the open else.

viewtopic.php?t=53407 is the solution.
TJH
Forum Newbie
Posts: 2
Joined: Sat Aug 12, 2006 12:55 pm

Post by TJH »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

     You should write this code in only one file. It shoud be in header.php.

Code: Select all

<?php 
$dir = "install/"; 
if (is_dir($dir)) { 
echo "THE INSTALL DIRECTORY EXISTS, YOU MUST REMOVE IT BEFORE YOU CONTINUE."; 
exit;
} 


 Cheers..  

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply