Jump to content

Need Help W/ Functions


Unholy Prayer

Recommended Posts

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 the
string with all the preset functions that
want 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 end

return $string;
# retrun the cleaned string
}

?>
<?php
/*
This function will allow you to show and log
users 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 time

mysql_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 loop

echo stripslashes($row['username']);
# first echo the username

$i++;
# this is for the punctuation.
# Create a number to compare with the $count variable

if ($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?
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.