Help With IF/Then/Else statement *FIXED*

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrneo240
Forum Newbie
Posts: 1
Joined: Sun Nov 19, 2006 10:25 pm

Help With IF/Then/Else statement *FIXED*

Post by mrneo240 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Found out he problem the ip address was not in quotes now it is fixed

i have an IP logger that i have built upon. But i dont want it to log me so i changed the script from

Code: Select all

<? 
$filename = "counter.txt"; 
$filename2= "iplog.txt";
$item = $_POST['ghuta'];
$fp = fopen( $filename,"r"); 
$Old = fread($fp, 100); 
fclose( $fp ); 
$Old = split ("=", $Old, 5);
$NewCount = $Old[1] + '1';
$New = "counter=$NewCount";
$fp = fopen( $filename,"w+"); 
if (flock($fp, 2)) { 
fwrite($fp, $New, 100); } 
fclose( $fp ); 
print "counter=$NewCount"; 
$fp = fopen( $filename2,"a");
$string = "\r\nVisitor Number-$NewCount   IP Address-$item";
$write = fputs($fp, $string);
fclose($fp);
?>
which works perfectly (it logs everyone just fine)
and i get

Code: Select all

counter=13
and it writes into the log
so i changed it to

Code: Select all

<? 
$filename = "counter.txt"; 
$filename2= "iplog.txt";
$item = $_POST['ghuta'];
if ( $item == my ip address ) {
$item= "I Visited My Own Site";
$fp = fopen( $filename2,"a");
$string = "\r\nVisitor Number-$NewCount   $item";
$write = fputs($fp, $string);
fclose($fp);
} else {
$fp = fopen( $filename,"r"); 
$Old = fread($fp, 100); 
fclose( $fp ); 
$Old = split ("=", $Old, 5);
$NewCount = $Old[1] + '1';
$New = "counter=$NewCount";
$fp = fopen( $filename,"w+"); 
if (flock($fp, 2)) { 
fwrite($fp, $New, 100); } 
fclose( $fp ); 
print "counter=$NewCount"; 
$fp = fopen( $filename2,"a");
$string = "\r\nVisitor Number-$NewCount   IP Address-$item";
$write = fputs($fp, $string);
fclose($fp);
}
?>
then i get

Code: Select all

Parse error: syntax error, unexpected T_DNUMBER in /home/www/neohosting.awardspace.co.uk/ip/counter.php on line 5
and that doesn't log anyone, not me not anyone else
and i dont understand why
if you want to see the flash here is a link http://neohosting.awardspace.co.uk/ip/get.html (that is the working one)
and here is the broken one http://neohosting.awardspace.co.uk/ip/broke.html
can someone please explain why the top one doesn't work


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply