Zezombia Posted August 25, 2008 Share Posted August 25, 2008 I just started php a couple of days ago. Probably would of started sooner if I could install php on my localhost. Anyway I made this code: <?php $ip = isset($_SERVER['REMOTE_ADDR']; $file = fopen("counter.txt", "r"); $bytes = 256; $counts = fread($file, $bytes); fclose ($file); $file2 = fopen ("ips.txt", "r"); $fileip = fread($file2, $bytes); if( $ip == $fileip) { echo "You have already been counted\n"; echo "Total people counted: " . $counts . "\n"; echo "See currents results here: http://zezombia.themavesite.com/browser-count/browsers.txt"; return false; } fclose ($file2); $file3 = fopen ("ips.txt", "w+"); fwrite ($file3, $fileip . $ip . "\n"); fclose ($file3); $file4 = fopen ("counter.txt", "w+"); fwrite ($file4, $counts + 1); fclose ($file4); $file5 = fopen ("browsers.txt", "w+"); $browsers = fread($file5, $bytes); fwrite ($file5, $browsers . $_SERVER['HTTP_USER_AGENT'] . "\n"); fclose ($file5); echo "You have been counted!\n"; echo "Total people counted: " . $counts . "\n"; echo "See currents results here: http://zezombia.themavesite.com/browser-count/browsers.txt"; ?> What's wrong: 1) When the page loads, it dosn't say: message 1 message 2 message 3 It says: message 1 message 2 message 3 2) When it saves what browser they were in, it goes over the last saved one instead of putting it on a new line. 3) Because the IP file holds more then one IP, it checks everything. That gives no help at all from people who want to refresh the page a ton. How do I make it check every ip on the list (one per line)? Also could you help me with it just saying Internet Explorer or Firefox instead of: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 Quote Link to comment https://forums.phpfreaks.com/topic/121187-something-wrong-with-code/ Share on other sites More sharing options...
sKunKbad Posted August 25, 2008 Share Posted August 25, 2008 1) instead of using /n try using <br /> 2) try changing your fopen mode from w+ to a+ 3) if you are going to record IP addresses, and then you are going to check against that record, you should be saving them as csv or using some delimiter. When you fread, use strstr to check for the IP match. This is really not the easiest or best way to do what you are trying to accomplish. Using mysql would be easier, but I realize you are just learning so at least check it out. Quote Link to comment https://forums.phpfreaks.com/topic/121187-something-wrong-with-code/#findComment-624740 Share on other sites More sharing options...
cooldude832 Posted August 25, 2008 Share Posted August 25, 2008 its \n not /n first off and the people are right in a browser the data is rendered as xhtml (or html) and the \n character is treated as a new line character (carriage return) in the source code meaning that the actual code being rendered has a carriage return added. To get a carriage return into the outputted rendering the <br /> is needed as stated. Quote Link to comment https://forums.phpfreaks.com/topic/121187-something-wrong-with-code/#findComment-624741 Share on other sites More sharing options...
ratcateme Posted August 25, 2008 Share Posted August 25, 2008 i can't see where it ouputs message 1 ... but try adding this to the top echo "<pre>"; for the browser info have a look at this http://us3.php.net/function.get-browser also read the note at the bottom you have to make sure you specify a browscap file in your php.ini the php page has a link to a site you can download one from but this looks like a really big job for files you could do this in a lot less code and a lot less hassle with a database have you looked at mysql (it is free) Scott. Quote Link to comment https://forums.phpfreaks.com/topic/121187-something-wrong-with-code/#findComment-624742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.