Forum Moderators: coopster

Message Too Old, No Replies

php parsing error

         

nafp

3:51 am on Apr 2, 2008 (gmt 0)

10+ Year Member



I'm new to php and am unable to resolve the following error message:

Parse error: syntax error, unexpected T_STRING in /nfs/aesop01/hw11/d53/einet/lib/global-einet.class.php on line 196

Would really appreciate your help.
Thanks,
nafp

Here's the code:

<?php
class einet {
var $title; // page title
var $body; // HTML
var $nav = '';
var $newsNav = ''; //upper right hand corner links for newsbriefs
var $set; // settings
var $netid; // user's UWNetID, if applicable
var $isAdmin = false; // working group access
var $isTrueAdmin = false; // site admin access (e.g., for jwerle)
var $mysql = false; // connected to database?
var $user_id = false; // logged in user (set by cookie)
var $queries = array(); // save SQL queries for debugging purposes
"global-einet.class.php" 488L, 11503C

// declare yo'self!
function einet() { // constructor
// declare settings
include SITE_ROOT . 'lib/settings.inc.php';
$this->set = $set;

if ($_SERVER['HTTP_HOST'] == '127.0.0.1') $_SERVER['REMOTE_USER'] = 'jjellisn'; // local testing

if (isset($_SERVER['REMOTE_USER'])) $this->netid = $_SERVER['REMOTE_USER']; // for UWNetID authentication
if (isset($_COOKIE['u'])) $this->user_id = (int)($_COOKIE['u']);
}
// perform MySQL query. Establishes db connection if needed
function query($query) {
if (!$this->mysql) $this->connectDatabase();
$this->queries[] = $query; // debugging
$result = mysql_query($query) or die ('<font color=red><b>Error:</b> Invalid query.</font> MySQL said:<br><br><b><tt>' . mysql_error());
return $result;
}
// connect to db
function connectDatabase() {
if (!mysql_connect($this->set['db_host'],$this->set['db_user'],$this->set['db_pass'])) {
//mail($set['admin_email'],'EINET DATABASE IS DOWN!','Could not connect to: ' $set['db_host']);
die('Could not connect to MySQL database: <br><tt> ' . mysql_error());
}
mysql_select_db('einet');
$this->mysql = true;
}
// prepare nav bar; display header footer w/body
function display() {
$action = get_class($this);
if(isset($_GET['view']) && $_GET['view']=='all') $action .= '&view=all';//custom link for searching newsbriefs
$subLink = isset($_GET['sub'])?$_GET['sub']:'';
if(isset($_GET['view']) && $_GET['view']!='all'){
$action .= '&view=all';//custom link for searching newsbriefs
$subLink = 'past';
}
$pages = array(
'home' => 'Home',
'flu' => 'Avian Influenza and EINet',
'symposium' => 'Virtual Symposium',
'about' => 'About APEC-EINet',
'builder&view=all' => 'Newsbriefs',
'partner' => 'APEC Economies',
'peopledir' => 'People Directory',
'teach' => 'Teaching & Learning',
'libresource' => 'Research Resources',
'contact' => 'Contact Us',

//'doclib' => 'Document Library',

//'meeting' => 'Meeting Minutes',

//'news' => 'Newsletter',

);

$subTeach = array(); //jw removed: 'infecourse'=>'EIC'
$subLib = array('libsearch'=>'Library Search', 'distopics'=>'Disease Topics');
$subPartners = array(); // jw removed: 'part1'=>"Partner 1",'part2'=>'Partner 2', 'part3'=>'Partner 3'
$subAbout = array('docs'=>'Library'); //jw removed: 'goals'=>'Goals',
$subBriefs = array('past'=>'Browse', 'search'=>'Search');
$subAdmin = array('stats'=>'Site Stats','emailer'=>'Email Newsbriefs','track'=>"Newsbrief Tracker");

if ($this->isAdmin) $pages['doclib'] = 'Document Library';
if ($this->isAdmin) $pages['event']= 'APEC-EINET Activities';
if ($this->isTrueAdmin) $pages['builder'] = 'Newsbrief Builder';
if ($this->isTrueAdmin) $pages['admin'] = 'Admin';

foreach($pages as $page => $label) {
$isActive = ($page == $action) ? ' class="active"' : '';$subNav = '';
if($page==$action){//only display subnav for the current page
$sub = array();
switch($action){//switch arrays for the correct sub nav
case 'teach':
$sub = $subTeach;
break;
case 'libresource':
$sub = $subLib;
break;
case 'partner':
$sub = $subPartners;
break;
case 'about':
$sub = $subAbout;
break;
case 'builder&view=all':
$sub = $subBriefs;
break;
case 'admin':
$sub = $subAdmin;
break;
default:
break;
}
foreach($sub as $subPage => $link){
$isActiveSub = ($subPage == $subLink) ?' class="active"' : '';
$extra = ($subPage == $subLink) ?'&gt;&nbsp;' : '&bull;&nbsp;';
$temp = ($page) ? '?a=' . $page .'&sub='.$subPage: '/';
if($subPage == 'past' && !$this->isTrueAdmin) $subNav .= "<a id=navB href=".FORM_URI."browse.html $isActive>$extra Browse</a>";
else if($subPage == 'search' && !$this->isTrueAdmin) $subNav .= "<a id=navB href=".FORM_URI."search.html $isActive>$extra Search</a>";
else if($subPage == 'stats'){
$subNav .='<a id=navB target = blank href="http://depts.washington.edu/einet/webstats"' . $isActive . '>'.$extra.'&nbsp;' . $link . '</a>';
}else{
$subNav .='<a id=navB href="' . $temp . '"' . $isActive . '>'.$extra.'&nbsp;' . $link . '</a>';
}
}

//htaccess file uses mod_rewrite to redirect the page so setup the link so the rewrite catches it
$link = ($page && $this->isTrueAdmin) ? FORM_URI .'?a=' . $page : FORM_URI."$page.html";
if($page == 'builder&view=all' && !$this->isTrueAdmin)$link = FORM_URI . 'newsbriefs.html';
$this->nav .= '<a href="' . $link . '"' . $isActive . '>' . $label . '</a>'.$subNav;
}
// $sql = "SELECT newsbrief_id FROM newsbrief ORDER BY newsbrief_id DESC";
// $sql = $this->query($sql);
// $r = mysql_fetch_array($sql);
// $newsbrief_id = $r['newsbrief_id'];
$currentLink =($this->isTrueAdmin)?"<a href='".FORM_URI."?a=builder&view=all'>":"<a href='".FORM_URI."newsbriefs.html'>";

$browseLink =($this->isTrueAdmin)?"<a href='".FORM_URI."?a=builder&view=all&sub=past'>":"<a href='".FORM_URI."browse.html'>";
$searchLink =($this->isTrueAdmin)?"<a href='".FORM_URI."?a=builder&view=all&sub=search'>":"<a href='".FORM_URI."search.html'>";
$viewLink =($this->isTrueAdmin)?"<a href='".FORM_URI."?a=track&sub=view'>":"<a href='".FORM_URI."viewed.html'>";
$emailLink =($this->isTrueAdmin)?"<a href='".FORM_URI."?a=track&sub=email'>":"<a href='".FORM_URI."emailed.html'>";
$this->newsNav = "<br>&nbsp;<b>Newsbrief Quick Links</b>".
"<p><ul class=newsbrief>
<li id=bullet>$emailLink Most Emailed</a></li><li id=bullet>$viewLink Most Viewed</a></li><li>$currentLink Current Newsbrief</a></li><li>$browseLink Browse Newsbriefs</a></li>".
"<li>$searchLink Search Newsbriefs</a></li><li><a href='".FORM_URI."?a=subscribe'>Subscribe/Unsubscribe</a></li></ul><br>";
if(!isset($_GET['a']) ¦¦ $_GET['a']!='printArticle' ) include SITE_ROOT . 'lib/inc/page-control.inc.php';
else include SITE_ROOT . 'lib/inc/print-control.inc.php';
if ($_SERVER['HTTP_HOST'] == '127.0.0.1') { // local testing; show MySQL queries
echo '<div style="padding:15px"><tt>';
echo '<h4>' . count($this->queries) . ' queries total</h4><ol type=1>';
foreach ($this->queries as $query) {
echo '<li>' . $query;
}
echo '</ol>';
}
}
// display login form; login user
function loginForm() {
"<p><ul class=newsbrief>
<li id=bullet>$emailLink Most Emailed</a></li><li id=bullet>$viewLink Most Viewed</a></li><li>$currentLink Current Newsbrief</a></li><li>$browseLink Browse Newsbriefs</a></li>".

"<li>$searchLink Search Newsbriefs</a></li><li><a href='".FORM_URI."?a=subscribe'>Subscribe/Unsubscribe</a></li></ul><br>";
if(!isset($_GET['a']) ¦¦ $_GET['a']!='printArticle' ) include SITE_ROOT . 'lib/inc/page-control.inc.php';
else include SITE_ROOT . 'lib/inc/print-control.inc.php';
if ($_SERVER['HTTP_HOST'] == '127.0.0.1') { // local testing; show MySQL queries
echo '<div style="padding:15px"><tt>';
echo '<h4>' . count($this->queries) . ' queries total</h4><ol type=1>';
foreach ($this->queries as $query) {
echo '<li>' . $query;
}
echo '</ol>';
}
}
// display login form; login user
function loginForm() {
Enter the "exit" command, to return to the menu environment.
return;
} else {
$this->body .=
'<font color=red>Email not found.</font> Please try again or <a href="?a=peopledir&s=new">add</a> yourself to the people directory.<br><br>';
}
//}
/*$this->body .=
'
Please enter in your email address below:
<form action="' . FORM_URI . '" method="post">
Email: <input type="textbox" name="email" size=30 value="' . $email . '"> <input type="submit" name="login" value="Login">
</form>';*/
}
function logIp($id, $type){
//grab the users ip, check if they have visted today (update if they have otherwise insert)
$ip = $_SERVER['REMOTE_ADDR'];
$date = date('Y-m-d');
$r= mysql_fetch_array($this->query("SELECT times_visited, pages, log_id FROM ip_log WHERE date='$date' AND ip_address = '$ip'"));
if(!$r){//no entry found setup insert
$temp = explode('.',$ip);
//convert from ip address to ip number
$ipNumber =($temp[0]*16777216)+($temp[1]*65536)+($temp[2]*256)+$temp[3];
$query = $this->query("SELECT country_code2 FROM iptocountry WHERE ip_from <='$ipNumber' AND ip_to>='$ipNumber'
LIMIT 0,1");
$r = mysql_fetch_array($query);
$sql = "INSERT INTO ip_log (ip_address, date, times_visited, pages, country_code2) VALUES ('$ip','$date','1','$type.$id','{$r['country_code2']}');";
}else{//entry found setup update
$timesVisited = $r['times_visited']+1;
$pages = $r['pages'] .",$type.$id";
$sql = "UPDATE ip_log SET times_visited='$timesVisited', pages='$pages' WHERE log_id = {$r['log_id']}";
}
//run query
//echo $sql;
$this->query($sql);
Enter the "exit" command, to return to the menu environment.
}
//run query
//echo $sql;
$this->query($sql);

$r= mysql_fetch_array($this->query("SELECT times_visited, log_id FROM log_articles WHERE date='$date' AND action = '$type' AND article_id='$id'"));
if(!$r){//no entry found setup insert
$sql = "INSERT INTO log_articles (article_id, date, times_visited, action) VALUES ('$id','$date','1','$type');";
}else{//entry found setup update
$timesVisited = $r['times_visited']+1;
$sql = "UPDATE log_articles SET times_visited='$timesVisited' WHERE log_id = {$r['log_id']}";
}
$this->query($sql);
}
}
?>

mikhaill

6:25 am on Apr 2, 2008 (gmt 0)

10+ Year Member



Look right after all the var settings...

...snip...

var $user_id = false; // logged in user (set by cookie)
var $queries = array(); // save SQL queries for debugging purposes
"global-einet.class.php" 488L, 11503C

/\---- what's that line doing there? Is that include gone wrong? a random line that just appeared? That's what's causing the error.

PHP_Chimp

10:09 am on Apr 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You also have
include SITE_ROOT . 'lib/settings.inc.php';

Have you already define [uk3.php.net]d SITE_ROOT? (it may have been in there, but there was sooooo much code)
Or do you mean $_SERVER['SITE_ROOT']? Although this is not guaranteed to be set, as it is not in the list of predefined variables [uk3.php.net]. So you may want to think about building it, so that your application is more portable.

From the manual (users comments, in this case) -

$host = $_SERVER['HTTP_HOST'];
$uri = rtrim($_SERVER['PHP_SELF'], "/\\");
$GLOBALS['SITE_ROOT'] = "http://$host$uri";