Unholy Prayer Posted November 26, 2006 Share Posted November 26, 2006 Ok, I got this from a tutorial from a different website, but their site is too inactive to get any help from them. I'm using their members system tutorial and the part where it displays the users that are online won't work. This is the error message I'm getting:[quote]Fatal error: Cannot redeclare online() in /home/dev/public_html/portal/functions.php on line 8[/quote]This is my code:[code]<?php/*First, I want to set a function to clean thestring with all the preset functions thatwant in one line.*/function clean($string) {# I've named the function clean()$string = addslashes($string);# addslashes to prevent SQL injections$string = strip_tags($string);# strip any tags$string = htmlspecialchars($string);# set any html left over to special characters$string = trim($string);# trim the string of any unwanted spaces at the start or endreturn $string;# retrun the cleaned string}?> <?php/*This function will allow you to show and logusers that are online.*/function online($id) {# create a function called online();/*To register a user as online..*/if (!empty($id)){# first check to see if the user is logged in$time = time();# set a new timemysql_query("UPDATE `users` SET `time` = '$time' WHERE `id` ='".$id."' LIMIT 1");# update the row of the online user setting time as the current time stamp}/*Now to display the online users*/$online_time = 300;# 300 is 5 minutes$check_time = time() - $online_time;# take $online_time off the current time for the query$query = "SELECT * FROM `users` WHERE time > '$check_time'";$query = mysql_query($query);# get the users set as online by getting users with their online time# more than the current time minus the online time$count = mysql_num_rows($query);# count the total online users$s = ($count > 1) ? "s " : " ";# this is to be next to "User".# If $count is more than one add an 's ', else add a " "echo $count.' User'.$s.'Online<br />';# Format: "# User(s) Online"while ($row = mysql_fetch_array($query)){# now to output the usernames, start a while loopecho stripslashes($row['username']);# first echo the username$i++;# this is for the punctuation.# Create a number to compare with the $count variableif ($i == $count){# $i == $count, use a full stop$add = ".";}elseif ($i == ($count - 1)){# if $i == $count - 1, use "and"$add=" and ";}else {# else, it must be a comma$add=", ";}echo "$add";# echo the $add variable}# end the while loop}?> [/code]Can someone please help me? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 26, 2006 Share Posted November 26, 2006 The function "online()" was already declared earlier in the script execution. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted November 26, 2006 Share Posted November 26, 2006 just wondering, but that file you posted is it functions.phpif not then in functions.php they have a function called online() and in that file another one... 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.