homepage Welcome to WebmasterWorld Guest from 54.161.166.171
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Parse error: syntax error, unexpected T STRING
I am getting an error for a simple php script that logs visits to my site.
rominosj




msg:4518524
 2:40 am on Nov 13, 2012 (gmt 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);
?>

 

incrediBILL




msg:4518527
 2:43 am on Nov 13, 2012 (gmt 0)

The "iif" is obviously one problem.

rominosj




msg:4518528
 2:44 am on Nov 13, 2012 (gmt 0)

Can you please elaborate on that?

g1smd




msg:4518529
 2:54 am on Nov 13, 2012 (gmt 0)

On line 4 the IIF should be IF.

rominosj




msg:4518533
 3:09 am on Nov 13, 2012 (gmt 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

rominosj




msg:4518534
 3:11 am on Nov 13, 2012 (gmt 0)

I read that iifis part of PHPKit. It stands for Immediate If.

incrediBILL




msg:4518569
 3:42 am on Nov 13, 2012 (gmt 0)

Well perhaps you should've mentioned PHPKIT to start with because unless there's an included iif() function somewhere, that's a problem.

swa66




msg:4518697
 10:32 am on Nov 13, 2012 (gmt 0)

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

(expr1) ? (expr2) : (expr3)


Ref: [php.net...]

vincevincevince




msg:4522204
 3:07 pm on Nov 24, 2012 (gmt 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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved