Click to See Complete Forum and Search --> : Updated links
MacMyDay
09-28-2003, 04:27 PM
I have my sidebar with links for the user, which they must be logged in to get to. What I want is that for the news section, if it's been updated since the user was last there, then the link to the news page appears in a different colour. I've seen it on some websites, yet have no clue how it works. I'd assume it would be with cookies, yet my experience with them is very small.
Thanks in advance.
How are you getting the links? Are you pulling them from a database, or is it a static file?
MacMyDay
09-29-2003, 01:13 AM
It's just a static file
MacMyDay
09-30-2003, 02:19 AM
Any ideas on this one? I could change it to be in the database if that would help with it.
It would really be quite easy, if you have a way to display the date you added the links. Even pulling them from a .txt file. I'll make something up real quick (using a .txt file) and you can look at that...
Ok, something like this should work fine:
<?PHP
$file = "links.txt"; #path to your file
if (isset($_COOKIE['lastvisit'])) { #get the cookies time (last visit time);
$time = $_COOKIE['lastvisit'];
}
else { #if no cookie was set
$month = date("n");
if (date("j") < 15) { #if day of the month is less than 15, use previous month
$month--;
}
$time = mktime(0,0,0,$month); #set $time to this month or last month (depending on if statement above)
}
setcookie("lastvisit", time()+3600, time()+60*60*24*365, "/"); #set time to time + 1 hr (so links don't change from new if they refresh)
$links = file($file);
foreach ($links as $link) { #loop through the links
list ($url, $modtime) = split("\\|", $link); #split at the |
if ($modtime > $time) { #if $modtime (taken from the .txt file) is greater than $time (taken from cookie or default value)
echo "<a href=\"$url\">$url</a> <span style=\"color: red; font-size: 10px; font-family:Verdana, Arial, Helvetica, sans-serif; vertical-align:super;\">new</span><br>";
}
else {
echo "<a href=\"$url\">$url</a><br>";
}
}
?>
and the file I was using for links.txt
http://www.webdevfaqs.com|2064927468
http://www.infinitypages.com|1064927468
http://www.w3c.org|0064927468The numbers after the pipe are a unix timestamp. The first one is set to a time way, way in the future (so you will see what new links look like), the middle one was current (at least when I was working ont it) and the last one is set to a time in the way in the past so you will see what they look like if the links are old...