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

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

10+ Year Member



 
Msg#: 4518522 posted 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

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



 
Msg#: 4518522 posted 2:43 am on Nov 13, 2012 (gmt 0)

The "iif" is obviously one problem.

rominosj

10+ Year Member



 
Msg#: 4518522 posted 2:44 am on Nov 13, 2012 (gmt 0)

Can you please elaborate on that?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4518522 posted 2:54 am on Nov 13, 2012 (gmt 0)

On line 4 the IIF should be IF.

rominosj

10+ Year Member



 
Msg#: 4518522 posted 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

10+ Year Member



 
Msg#: 4518522 posted 3:11 am on Nov 13, 2012 (gmt 0)

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

incrediBILL

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



 
Msg#: 4518522 posted 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

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



 
Msg#: 4518522 posted 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

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



 
Msg#: 4518522 posted 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