Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Parse error: syntax error, unexpected T STRING

I am getting an error for a simple php script that logs visits to my site.

     
2:40 am on Nov 13, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 28, 2004
posts:134
votes: 0


Hi,

I am getting the error:

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\mydomain\logs.php on line 5

for this code below. It i a simple php log script that will let me see who is visiting my site, what page, etc.


<?php
// Getting the information
$ipaddress = $_SERVER['REMOTE_ADDR'];
$page = "http\://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
$page .= iif(!empty($_SERVER['QUERY_STRING']), '?($_SERVER['QUERY_STRING'])',"");
$referrer = $_SERVER['HTTP_REFERER'];
$datetime = mktime();
$useragent = $_SERVER['HTTP_USER_AGENT'];
$remotehost = @getHostByAddr($ipaddress);
// Create log line
$logline = $ipaddress . "|" . $referrer . "|" . $datetime . "|" . $useragent . "|" . $remotehost . "|" . $page . "\n";

// Write to log file:
$logfile = "c:/wamp/www/mydomain/logfile.txt";

// Open the log file in “Append” mode
if (!$handle = fopen($logfile, 'a+')) {
die("Failed to open log file");
}

// Write $logline to our logfile.
if (fwrite($handle, $logline) === FALSE) {
die("Failed to write to log file");
}

fclose($handle);
?>
2:43 am on Nov 13, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14624
votes: 88


The "iif" is obviously one problem.
2:44 am on Nov 13, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 28, 2004
posts: 134
votes: 0


Can you please elaborate on that?
2:54 am on Nov 13, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


On line 4 the IIF should be IF.
3:09 am on Nov 13, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 28, 2004
posts: 134
votes: 0


I think you meant line 5, and that iif is fine according to some readings I found at other sites, but I can't figure out if I am missing a quote, or parentheses or what.

However, to verify your request I changed it to if, and I got this error now:

Parse error: syntax error, unexpected T_IF in C:\wamp\www\mydomain\logs.php on line 5
3:11 am on Nov 13, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 28, 2004
posts: 134
votes: 0


I read that iifis part of PHPKit. It stands for Immediate If.
3:42 am on Nov 13, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14624
votes: 88


Well perhaps you should've mentioned PHPKIT to start with because unless there's an included iif() function somewhere, that's a problem.
10:32 am on Nov 13, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 7, 2003
posts:4783
votes: 0


PHP has a ternary operator ... why not use it instead of "iif"

(expr1) ? (expr2) : (expr3)


Ref: [php.net...]
3:07 pm on Nov 24, 2012 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


Yes, you can't just swap iif for if; you'll have to change it to what swa66 said, or break it out into a separate line.

Alternatively, I think you are missing PHPKIT?