Primal Hurt Pr1m0 Posted June 25, 2010 Share Posted June 25, 2010 hello all..... I need help getting my php script to just recording clicks to recording they to certain variables during certain times of year. I need to record clicks from Jan-Mar, Apr-june, July-Sept, and Oct-Dec. Here is the script I currently have that counts the times its accessed, increments the value in a text file then redirects to the clicked link. <?php $file = 'someTextFile.txt'; $data = @file($file); $data = $data[0]; if($handle = @fopen($file, 'w')){ $data = intval($data); $data++; fwrite($handle, $data); fclose($handle); } // actual target location header('Location: http://www.somewhere.com'); ?> Please any positive input would be greatly appreciated as I am new to writing php scripts Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/ Share on other sites More sharing options...
premiso Posted June 26, 2010 Share Posted June 26, 2010 You will be much better off learning SQL and using a MySQL database for handling this. A flat file will be overly slow to parse and if you are trying to read back statistics another person cannot actively write to that file while it is open. After you stopped wanted to just track "clicks" is about when you need to goto a MySQL DB. Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077578 Share on other sites More sharing options...
ram4nd Posted June 26, 2010 Share Posted June 26, 2010 Isn't it easier to use Google Analytics? Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077579 Share on other sites More sharing options...
Primal Hurt Pr1m0 Posted June 26, 2010 Author Share Posted June 26, 2010 @premiso- not being able to write while its open is not a problem. the site does not get high volume of traffic. also please read on @ram4nd - it may be but its not what the site owner wants, she currently has a link to the text file which she sees when she wants, so I am stuck just modifying the currently implemented method Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077591 Share on other sites More sharing options...
premiso Posted June 26, 2010 Share Posted June 26, 2010 Well why not just save the text file by month using date to get the current month. On a new month it writes to a new text file. Then to get the stats you just have to open the 3 months and count that way. Simple and easy. Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077597 Share on other sites More sharing options...
Primal Hurt Pr1m0 Posted June 26, 2010 Author Share Posted June 26, 2010 Well thats what I want to accomplish without having to do it manually and not monthly but every three months. it that possible? Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077668 Share on other sites More sharing options...
premiso Posted June 26, 2010 Share Posted June 26, 2010 $months = array('jan-mar' => array('January', 'February', 'March'), 'apr-jun' => array('April', 'May', 'June'), 'jul-sep' => array('July', 'August', 'September'), 'oct-dec' => array('October', 'November', 'December')); $currentMonth = date('F'); foreach ($months as $file => $month) { if (in_array($currentMonth, $month)) { $fileName = $file . ".txt"; break; } } // file code below Not the best way, but one way to do it. Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077704 Share on other sites More sharing options...
Primal Hurt Pr1m0 Posted June 27, 2010 Author Share Posted June 27, 2010 ok, could you walk me through that script please.... also how would that integrate with what i have. Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077746 Share on other sites More sharing options...
premiso Posted June 27, 2010 Share Posted June 27, 2010 If you cannot figure that out, I would say you should hire someone to do the code for you, or take the time to learn. Good luck. Link to comment https://forums.phpfreaks.com/topic/205900-need-help-recording-clicks-by-yearly-quarters-newbie/#findComment-1077757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.