Welcome to WebmasterWorld Guest from 54.226.143.14

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)

10+ Year Member



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)

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



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

10+ Year Member



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

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



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

10+ Year Member



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)

10+ Year Member



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

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



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)

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



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)

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



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?
 

Featured Threads

Hot Threads This Week

Hot Threads This Month