Jump to content

Advice on new categories added


graham23s

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.