xcandiottix Posted March 26, 2010 Share Posted March 26, 2010 I have a comment section on my site. I would like to record the date someone first logs on to my site, add a point to their table id everytime they comment, disallow commenting after 5 points, delete thier ip after 24 hours. So far, I have this: $ipi = getenv("REMOTE_ADDR"); $sql = "SELECT * FROM iplog WHERE Ip = '$ipi'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); if (isset($row['Ip'])) { } else { mysql_query("INSERT INTO iplog (Ip) VALUES ('$ipi')"); } In the INSERT command i'll insert the date but i have not used date functions before in php. Which date format will be the easiest to subtract from to find if their ip has been logged for 24 hours? And what would the code look like that subtracts their log in time to the current time? Thanks for any suggestions. -K.candiotti Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/ Share on other sites More sharing options...
RussellReal Posted March 26, 2010 Share Posted March 26, 2010 use sessions.. <?php // top of php files include('monitor.php'); ?> <?php // monitor.php session_start(); // turn the session into an object to avoid strict notices (unset keys) $user = (object) $_SESSION; if (isset($temp->logged_in)) { if ($temp->logged_in <= (time() - (24 * 60 * 60))) { $temp = null; } } else { $temp->logged_in = time(); $temp->posts = 0; } $_SESSION = (array) $temp; ?> and then whenever the user posts a post increase $_SESSION['posts'] and check if its greater than 5.. if its greater than five don't continue with the comment.. Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032479 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Author Share Posted March 26, 2010 I haven't used sessions before, but willing to give it a shot as it seems it will work better. The session will track the individual user that accesses the site no matter which page they are on (because of monitor.php at the top)? And what happens if they X out of their web browser and come back? Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032481 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Author Share Posted March 26, 2010 I have a warning: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/x/c/a/xcandiottix/html/chart.php:11) in /home/content/x/c/a/xcandiottix/html/monitor.php on line 3 Do you know what could be causing this? I copied your code directly in with out edit. Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032490 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Author Share Posted March 26, 2010 Ahh.. there was a blank line above the <?php // top of php files include('monitor.php'); ?> now it works =D Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032496 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Author Share Posted March 26, 2010 OKAY .. final question before I have this thing conquered. For testing I've made a page that echos $_SESSION['posts'] then adds 1 to it then reechos it so i get: 01 on screen. If i leave this page and come back i would expect to see: 12 but instead I get 01 again. How to I send the +1 to $_SESSION['posts'] correctly? I tried: echo $_SESSION['posts']; $_SESSION['posts']++; echo $_SESSION['posts']; but that doesn't work... Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032501 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2010 Share Posted March 26, 2010 You cannot use session variables to enforce these type of restrictions because all someone needs to do is drop the session id and they get a completely new set of chances. You must record and check the information in a database table. Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032506 Share on other sites More sharing options...
xcandiottix Posted March 26, 2010 Author Share Posted March 26, 2010 I have a table at the ready, I just have no idea how to get $_SESSION to talk to the table. Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032507 Share on other sites More sharing options...
xcandiottix Posted March 27, 2010 Author Share Posted March 27, 2010 Alrighty, I managed to get the whole thing done with a small brick of code and a 4 column table. Didn't end up using a session though because I'm not that advanced yet ;p The (time() - (24 * 60 * 60)) was a HUGE help tho so thanks so much for that. -K.candiotti Quote Link to comment https://forums.phpfreaks.com/topic/196651-date-and-comparison/#findComment-1032558 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.