graham23s Posted July 3, 2007 Share Posted July 3, 2007 Hi Guys, when a user logs into my site i wanted to add a "JUST ADDED" sign next to categories uploaded since they last logged in, once they see the new categories the "JUST ADDED" sign dissapears, i'm not sure the best way to go about it and help would be great. cheers Graham Quote Link to comment Share on other sites More sharing options...
wcsoft Posted July 3, 2007 Share Posted July 3, 2007 You'd basically need some way to track 2 things: 1) The last time they visited your site. 2) The time that a category was created. You could do #1 with either a permanent cookie that you set when they visit. #2 would need to be done with a database. If you're using a db already for your categories, then you'd just add a timestamp that the category was created. Then basically, when the user visits your site you just do a comparison to see what categories have a timestamp greater than their last visit time. If any of them do, you'd display the "JUST ADDED" message. Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 3, 2007 Author Share Posted July 3, 2007 1 thing with my site mate if i login 2 days ago for example , i don't need to login again as the cookie remembers me, i updated the last_login field in mysql when people login but that only works when the cookie has expired and they need to login does that make a differenece to number 2? cheers Graham Quote Link to comment Share on other sites More sharing options...
wcsoft Posted July 3, 2007 Share Posted July 3, 2007 Yes, in that case, it wouldn't really reflect new categories. There are several ways to get around that. The easiest would be to modify your header code to set a cookie on each page load that is permanent, with the current timestamp, and use that for the comparison. With this, it doesn't matter if they are logged in or logged out, and it will store the true last visit time, since it updates on each page. Quote Link to comment Share on other sites More sharing options...
graham23s Posted July 16, 2007 Author Share Posted July 16, 2007 Hi, That sounds good and fairly easy lol not sure how to set another cookie from the one i already set in the login_check.php heres is my code: <?php include("includes/db_connection.php"); include("includes/constants.php"); $username = trim(strtolower(mysql_real_escape_string($_POST['username']))); $password = trim(strtolower(mysql_real_escape_string($_POST['password']))); if (empty($username) || empty($password)) { echo "Please fill in both fields."; exit; } ## check the user is in the database ############################################### $login_query = "SELECT username,password FROM `membership` WHERE `username`='$username' AND `password`='$password'"; $login_result = mysql_query($login_query) or die (mysql_error()); $is_greater_than_1 = mysql_num_rows($login_result); // was there a user found?...####################################################### if($is_greater_than_1 != 1) { echo "Sorry username and password combination not found."; exit; } else { ## User is logged in so Let's give him a cookie. ################################### setcookie ("member",$username,time()+1957240,"/"); ## a variable to hold the cookie ################################################### $member = $username; ## If cookie failed set a session...################################################ $_SESSION['member'] = 'member'; ## Update Login timer...############################################################ $timer_query = "UPDATE `membership` SET `login`=now() WHERE `username`='$username' AND `password`='$password'"; $timer_result = mysql_query($timer_query) or die (mysql_error()); if ($timer_result) { header("Location:my_account.php"); } } ?> and at the top of every protected page: <?php // For register_global on PHP settings////////////////////////////////////////////// $member = $_COOKIE['member']; session_start(); // you must put this to read session variables///////////////////// if (empty($member) || !isset($member)) // fail to read the browser cookie/////////// { // Try to read session if (empty($_SESSION['member']) || !isset($_SESSION['member'])) { header("Location: login.php"); // redirect user to login////////////////////// exit; } else { $member = $_SESSION['member']; } } ?> any help would be appreciated cheers Graham Quote Link to comment 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.