cyberdie Posted February 19, 2012 Share Posted February 19, 2012 Hi guys just wanted a quick fix as I dont know PHP, but all i was looking to do was load the following. I have a file called db.txt which has 0 numeric value and have sourced this code <?php$db = "db.txt"; // The database we created$handle = fopen($db, 'r+') ; // Open the db, read and be able to write to it$data = fread($handle, 512) ; // Get current count from the db$count = $data + 1; // Add in a count since it's being readprint $count; // Display current count on the web pagefseek($handle, 0) ; // Point back to the beginning of the filefwrite($handle, $count) ; // Save the countfclose($handle) ; // Close count?> I can have the counter work if I load counter.php however I want the counter embedded into the index homepage and the number increase on open, like a hit counter should. Please can someone provide the answer. Link to comment Share on other sites More sharing options...
niche Posted February 19, 2012 Share Posted February 19, 2012 You might have to wait awhile for an answer. Since you're new, you should know that it's considered discourteous to ask for help with someone else's script while avoiding the tutorials. The more learning you do before you ask, the faster and more meaningful the answer will be. So to get the learning started, how will you include your script in your index file and why are you using text? How else could you accomplish the same task? Your question gives you a great opportunity to be independent. It's like they say in the fishing business, Give him a fish and he'll eat for a day. Give him a fishing pole and help him understand how to use it and he'll eat for the rest of his like. W3schools gives poles to everyone that's willing to use them. Link to comment Share on other sites More sharing options...
Krewe Posted February 19, 2012 Share Posted February 19, 2012 I can't give the answer, but a huge flaw you are going to get is there is no "net' to catch the same user. You can spam the counter by just refreshing the page. Link to comment Share on other sites More sharing options...
niche Posted February 19, 2012 Share Posted February 19, 2012 Another reason to be as informed as possible. Link to comment Share on other sites More sharing options...
birbal Posted February 20, 2012 Share Posted February 20, 2012 you can use include() to include the counter.php page where it needs, better will be encapsulate it in a function aand calling it. Link to comment Share on other sites More sharing options...
cyberdie Posted February 20, 2012 Author Share Posted February 20, 2012 Appreciate the comments, although maybe not the patronising one, although that may because I'm not much of a fisherman. Appreciate that the PHP is flawed in terms of refresh of same user, although was just looking for a counter that would act as a guide. Worked it out though as needed to set home page as php and use birbal's include feature. Job Done. (stick of dynamite seems to do just as good a job) Link to comment Share on other sites More sharing options...
niche Posted February 20, 2012 Share Posted February 20, 2012 If I was patronising, I wouldn't have underlined, italicized and bolded the word include in post #2. Link to comment Share on other sites More sharing options...
cyberdie Posted February 21, 2012 Author Share Posted February 21, 2012 Haha I noticed thanks instead of a txt file is it better just to use HTML, what are the pros and cons? Link to comment Share on other sites More sharing options...
niche Posted February 21, 2012 Share Posted February 21, 2012 SQL would be one alternative (in all it's various forms - I use MYSQL), HTML, would not be an option since it doesn't handle variables per se. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.