LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-17-2008, 06:27 PM   #1
jouvert
LQ Newbie
 
Registered: May 2008
Posts: 10

Rep: Reputation: 0
Smile Parse error: parse error, unexpected '}' in /home/content


Hello:

I am a newbie here in the forum and hope to share the knowledge with one another:
However:
I have a challenge of a Parse error:

Parse error: parse error, unexpected '}' in index.php on line 46

Below is the copy of the index.php that is a challenge to fix.(atleast to me anyway) Hoping you can help me fix this thing. Please help me..

Best

Jimmy
------------------------------------------------------------
<?
//////////////////////////////////////////////////
// Admin area for worldwide path easy //
// V4.1- Sud, 09 Nov //
// (c) 2002 Peter J Harry. All rights reserved. //
// http://replytoDaddy.com //
//////////////////////////////////////////////////

// V1.0 - page reads all config variables and allows user to update them
// V1.1 - differentiate between boolean (show_ & use_) and text input
// V1.2 - list all files in includes/pages/ with option to edit pages
// V1.3 - additional Articles link for adding and editing articles
// V1.4 - templatefoldername readonly
// V1.5 - add username and password
// V1.6 - make compatible with older 'do not edit' versions of config.php
// V1.7 - submit button for deleting article, header and footer added

define('VERSION','V1.7 &copy; 2007 Simon B Kelly');

session_start();
if($_POST[user]) {
$_SESSION[username]=$_POST[user];
$_SESSION[password]=$_POST[pass];
}
$msg="";
$q=$_GET[q];
extract($_POST);
if($submit=="Update") {
$file = "";
foreach ($_POST as $key=>$value) {
if(substr($key,0,4)=="line" && $value>'') {
$file .= trim(urldecode($value))."\r\n";
}
}
foreach ($_POST as $key=>$value) {
if(substr($key,0,4)<>"line") {
if($value=="on") { $value="1"; }
$file = str_replace("##$key##",$value,$file);
}
}
$file = preg_replace('/(##[a-z_]*##)/','0',$file);
$filename = "../includes/config.php";
}
$_SESSION[username]=$username;
$_SESSION[password]=$password;
}
$filename = "../includes/config.php";
include ($filename);
$line = file($filename);

if($_SESSION[username]<>$username || $_SESSION[password]<>$password || $username=='' || $password=='') {
echo '<html><head></head><body><br><br><br><br><br><br><br><br><br><br>
<FORM action="index.php" method="POST">
<table align="center">
<tr><th colspan=2>This area is password protected!</th></tr>
<tr><td>Username:</td><td><INPUT type="text" name="user"></td></tr>
<tr><td>Password:</td><td><INPUT type="password" name="pass"></td></tr>
<tr><td colspan=2 align="right"><INPUT type="submit" name="submit" value="Login"></td></tr>
</table>
</FORM>
</body></html>';
exit;
}

?>

}
fclose($create_file);
$msg="File was created successfully!";
$template=$q;
$q="articles";
} else {
$msg="Please choose a valid filename using only letters, numbers, hyphens and underscores!";
$q="new";
}
}

if($submit=="Delete article") {
$filename = "../includes/articles/$template";
if(unlink($filename)) {
$msg="Successfully deleted file.";
} else {
$msg="Problems deleting file, please check permissions.";
}
$q="articles";
$template="";
}

if($submit=="Save page"||$submit=="Save article") {
if($submit=="Save page") { $template=$q; $filename = "../includes/pages/$q";
} else { $filename = "../includes/articles/$template"; }
}
}

$handler = @opendir("../includes/pages/");
if($q) { echo '<a href="index.php">'; } else { echo '<b>'; }
echo 'Site Settings';
if($q) { echo '</a> | '; } else { echo '</b> | '; }
while ($file = @readdir($handler)) {
if ($file != '.' && $file != '..') {
if($q==$file) {
echo '<b>'.$file.'</b> | ';
} else {
echo '<a href="index.php?q='.$file.'">'.$file.'</a> | ';
}
}
}
@closedir($handler);

if($q<>"articles") {
echo '<a href="index.php?q=articles">Articles</a> | ';
} else {
echo '<b>Articles</b> | ';
}
if($q<>"newarticle") {
echo '<a href="index.php?q=newarticle">New Article</a> | ';
} else {
echo '<b>New Article</b> | ';
}
if($q<>"keywords") {
echo '<a href="index.php?q=keywords">Keywords</a> | ';
} else {
echo '<b>Keywords</b> | ';
}
if($q<>"logout") {
echo '<a href="index.php?q=logout">Log Out</a><br><br>';
} else {
echo '<a href="index.php">Log in</a><br><br>';
$_SESSION[username]='';
$_SESSION[password]='';
echo '<em>You are now logged out!</em>';
exit;
}

if($msg) { echo '<em>'.$msg.'</em><br><br>'; }

if($q=="articles") {
$handler = @opendir("../includes/articles/");
while($file = readdir($handler)) {
if ($file != '.' && $file != '..') {
$files[] = $file;
}
}
sort($files);
for ($i=0; $i<count($files); $i++) {
if($files[$i]==$template) { $selected=" SELECTED"; } else { $selected=""; }
$select = $select . "<OPTION VALUE='$files[$i]'$selected>$files[$i]";
}
if($template=="") {
echo 'Choose the file you would like to edit from the drop-down box below:<p>';
}
echo '<FORM action="index.php?q=articles" method="POST">
<SELECT name="template">'.$select.'</SELECT>
<INPUT type="submit" value="Edit article">
<INPUT type="submit" name="submit" value="Delete article">
</FORM>';
if($template>"") {
$text = @file("../includes/articles/$template","r");
echo '<FORM action="index.php?q=articles" method="POST">
<INPUT type="hidden" name="template" value="'.$template.'">
<br><B>EDIT TEMPLATE</B> : '.$template.'
<br><TEXTAREA name="text" rows=20 cols=80>'.stripslashes(implode("",$text)).'</TEXTAREA>
<br><INPUT type="submit" name="submit" value="Save article">
</FORM>';
}
include("footer.php");
exit;
}

if($q=="newarticle") {
echo '<FORM action="index.php" method="POST">
<b>FILENAME:</b> <INPUT type="text" name="template" maxlength=32> (All Article pages will be given a <b>.txt</b> extension.)
<br><br>
<br><B>NEW TEMPLATE</B> : Enter the HTML for this Article in the box below:
<br><TEXTAREA name="text" rows=20 cols=80>'.$text.'</TEXTAREA>
<br><INPUT type="submit" name="submit" value="Create article">
</FORM>';
include("footer.php");
exit;
}

}
$text = @file($filename,"r");
echo '<b>EDIT PAGE</b> : '.$q.'
<FORM action="index.php" method="POST">
<INPUT type="hidden" name="q" value="'.$q.'">
<TEXTAREA name="text" rows=20 cols=80>'.stripslashes(implode("",$text)).'</TEXTAREA>
<br><INPUT type="submit" name="submit" value="Save page">
</FORM>';
include("footer.php");
exit;
}

$line = file($filename);
echo 'This page will allow you to update your site settings.
<p>
<FORM action="index.php" method="POST">
<table border=1 cellpadding=10 cellspacing=0>
<tr><td align="center">
<table border=0 cellpadding=2 cellspacing=0>
';
$l=0;
$donotedit=0;
while ($l<count($line)) {
// loop through file displaying comments and providing input boxes for user to make changes
$content = $line[$l];
$data = trim($content);
if($data > '' && $donotedit == 0) {
if( ereg('do not edit',$data)||ereg('$site ',$data) ) { $donotedit = 1; }
}
$char = substr($data,0,1);
if($donotedit==1) {
echo '<INPUT type="hidden" name="line'.$l.'" value="'.urlencode($content).'">
';
} else if($char=="/") { // it's a comment
echo '<INPUT type="hidden" name="line'.$l.'" value="'.urlencode($content).'">
<tr><td colspan=3>'.substr($data,2).'</td></tr>
';
} elseif($char=="$") { // it's a variable
$var = explode("\"",$data);
if(ereg(";",$var[0])) {
$data = str_replace('=','= "',$data);
$data = str_replace(';','";',$data);
$var = explode("\"",$data);
$var[1]=trim($var[1]);
}
$nws = str_replace(" ","",$var[0]);
if(substr($nws,-7)=="=array(") {
$data = "\r\n".$data;
// make sure data includes all elements in the array
while(!ereg(")",$data)) {
$l++;
$more = $line[$l];
$content .= $more;
$data .= "\r\n".trim($more);
}
$var[1] = trim(substr($data,strlen($var[0])));
$nws = substr(str_replace("=array(","",$nws),1);
$array=explode("'",$var[1]);
// check for associative array
for($g=0;$g<count($array);$g++) {
if(trim($array[$g])=="=>") {
$var[1]=trim($array[$g-1]);
$var[2]=trim($array[$g+1]);
$array[$g+1]="##".$var[1]."##";
} elseif(substr(trim($array[$g]),0,1)==",") {
// end of element, print result
$var[3]=trim(substr(str_replace("//","",trim($array[$g])),1));
if(substr($var[3],-1)==";") { $var[3]=substr($var[3],0,-2); }
echo '<tr><td align="right"><b>'.$nws.'</b> '.$var[1].'</td>
<td><INPUT type="text" name="'.$var[1].'" value="'.$var[2].'"></td><td>'.$var[3].'</td></tr>';
}
}
$array[0] = $var[0]."\r\n";
$data = implode("'",$array);
// echo '<TEXTAREA name="line'.$l.'" rows=3 cols=40>'.$data.'</TEXTAREA>';
echo '<INPUT type="hidden" name="line'.$l.'" value="'.urlencode($data).'">';
} else {
$var[0] = trim(substr(str_replace("=","",$var[0]),1));
$var[2] = trim(substr(str_replace("/","",$var[2]),1));
if(substr($var[0],0,5)=="show_" || substr($var[0],0,4)=="use_") {
echo '<tr><td align="right"><b>'.$var[0].' </b></td>
<td><INPUT type="checkbox" name="'.$var[0].'"';
if($var[1]==1) { echo ' CHECKED'; }
echo '></td>
<td> '.$var[2].'</td></tr>
';
} else {
if($var[0]=="templatefoldername") { $extra=' READONLY'; }
elseif(substr($var[0],0,1)=='_') { $extra=' size=2'; }
else { $extra=''; }
echo '<tr><td align="right"><b>'.$var[0].' </b></td>
<td><INPUT type="text" name="'.$var[0].'" value="'.$var[1].'"'.$extra.'></td>
<td> '.$var[2].'</td></tr>
';
}
$var[1] = "##".$var[0]."##";
$array = explode("\"",$data);
$array[1] = $var[1];
$data = implode("\"",$array);
echo '<INPUT type="hidden" name="line'.$l.'" value="'.urlencode($data).'">
';
}
} else { // it's something else
echo '<INPUT type="hidden" name="line'.$l.'" value="'.urlencode($content).'">
';
}
$l++;
}

?>
</td></tr>
</table>
<br><INPUT type="submit" name="submit" value="Update">
<br><br>
</td></tr>
</table>
</FORM>
<? include("footer.php"); ?>
 
Old 05-17-2008, 06:38 PM   #2
vadkutya
Member
 
Registered: Apr 2008
Distribution: slackware 10.2
Posts: 117

Rep: Reputation: 17
so why don't you just go to line 46 and check what the '}' is doing there? the prase error is quite clear on that matter . it is unmatched, i.e. it has no opening '{' corresponding to it.

there's a programming subforum here as well (http://www.linuxquestions.org/questions/programming-9/). please ask such questions there.

vadkutya

Last edited by vadkutya; 05-17-2008 at 06:42 PM.
 
Old 05-17-2008, 06:45 PM   #3
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
it looks like you have an extra '}' which appears on line 46. (or there is no corresponding '{')

Code:
 42 $filename = "../includes/config.php";
 43 }
 44 $_SESSION[username]=$username;
 45 $_SESSION[password]=$password;
 46 }
 47 $filename = "../includes/config.php";
 48 include ($filename);
 49 $line = file($filename);
The opening { to the if statement on line 28 is closed by the } on line 43 and then on line 46 we have another } which does not seem to have a corresponding {.

You may just try commenting line 46 and see how it goes.

Hope this helps.

FYI, when posting code it is preferred to place it within a "code" stanza to make it easier to read.

Code:
[ code ] ... [ / code ]

Edit1:
Beat me to it vadkutya.
End Edit1

Last edited by rayfordj; 05-17-2008 at 06:48 PM.
 
Old 05-17-2008, 06:55 PM   #4
jouvert
LQ Newbie
 
Registered: May 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Sorry to upset anyone. I am learning and ready to take the punches.

Thanks for your help I will try it.

Thanks for the link too.

Jimmy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected '/' - can anyone see the error in this code? v@ny@ Programming 8 04-03-2010 04:07 PM
What's the meaning of "PHP Parse error: parse error, unexpected $ in..." frandalla Programming 23 03-04-2009 12:34 PM
Parse Error: Unexpected $ markizano Programming 2 03-21-2008 12:24 PM
Parse error: parse error, unexpected $ in /home/content/d/o/m/domain/html/addpuppy2.p Scooby-Doo Programming 3 10-25-2007 09:41 AM
need help with "Parse error: parse error, unexpected T_STRING" coffee245 Programming 2 01-29-2007 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration