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 © 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"); ?>