PHP + Forms + Bad Luck
Posted: Thu Aug 08, 2002 5:23 am
Hey,
I'm new to PHP, and have been looking at both phpcomplete and the php.net online docs to help me along the way. I have most of my problems fixed, so no errors are generated when the page is loaded, but i'm missing two desirable effects, they are: 1. To read from the file, scanning for the IP address of the user, and 2. To write multiple IP addresses to the text file. I am going to paste my rather sloppy looking code, please, if you can, help me out. BTW, this code is used to log IPs and read them from a file, i'm using it to prevent cheating on a poll.
<?php
$filename = "ipdata.txt";
$fp = fopen($filename, "w+b");
$offset = 0;
while ($searchip = fgets($fp, 4096)); {
$query_str = '$HTTP_SERVER_VARS["REMOTE_ADDR"]';
$pos = ;
if ($pos == $HTTP_SERVER_VARS["REMOTE_ADDR"])
{ echo 'You have voted once, and cannot vote again'; }
elseif ($pos !== $HTTP_SERVER_VARS["REMOTE_ADDR"])
{ echo 'You have submitted your only allowed vote, below are the results';
fclose($fp); }
else ($pos !== $HTTP_SERVER_VARS["REMOTE_ADDR"]) ;
{ $fd = fopen($filename, "w+b");
fwrite($fd, $HTTP_SERVER_VARS["REMOTE_ADDR"]); }
fclose($fd); }
?>
I'm new to PHP, and have been looking at both phpcomplete and the php.net online docs to help me along the way. I have most of my problems fixed, so no errors are generated when the page is loaded, but i'm missing two desirable effects, they are: 1. To read from the file, scanning for the IP address of the user, and 2. To write multiple IP addresses to the text file. I am going to paste my rather sloppy looking code, please, if you can, help me out. BTW, this code is used to log IPs and read them from a file, i'm using it to prevent cheating on a poll.
<?php
$filename = "ipdata.txt";
$fp = fopen($filename, "w+b");
$offset = 0;
while ($searchip = fgets($fp, 4096)); {
$query_str = '$HTTP_SERVER_VARS["REMOTE_ADDR"]';
$pos = ;
if ($pos == $HTTP_SERVER_VARS["REMOTE_ADDR"])
{ echo 'You have voted once, and cannot vote again'; }
elseif ($pos !== $HTTP_SERVER_VARS["REMOTE_ADDR"])
{ echo 'You have submitted your only allowed vote, below are the results';
fclose($fp); }
else ($pos !== $HTTP_SERVER_VARS["REMOTE_ADDR"]) ;
{ $fd = fopen($filename, "w+b");
fwrite($fd, $HTTP_SERVER_VARS["REMOTE_ADDR"]); }
fclose($fd); }
?>