Jump to content


Online Users Error


6 replies to this topic

#1 Trix06

    Young Padawan

  • Members
  • Pip
  • 292 posts
  • Gender:Male
  • Location:NSW Australia
  • Interests:Web Design & Development, Graphic Design, Programming, Networking, Girls, The Beach, Amatuer Radio Communications and more.

Posted 01 October 2006 - 02:23 AM

			  <?php
				  include ("config.php");
session_start();
function update_sessions()
{
	$sid = session_id();
	if($_SESSION['sitename_online'] == "1")
	{
		mysql_query("UPDATE `sessions` SET `time` = '". time() ."' WHERE `sid` = '$sid'") or die(mysql_error());
	}
	else
	{
		$_SESSION['sitename_online'] = 1;
		mysql_query("INSERT INTO `sessions` SET `time` = '". time() ."', `sid` = '$sid'") or die(mysql_error());
	}
}
function get_onlineusers()
{
	$min = time() - 301;
	mysql_query("DELETE FROM `sessions` WHERE `time` <= '$min'") or die(mysql_error());
	$query = mysql_query("SELECT COUNT(sid) FROM `sessions`");
	$num = mysql_fetch_row($query);
	return($num[0]);
}
update_sessions();
echo "There are currently ". get_onlineusers() ." users online.";
?>

I used this code to show how many users are online, but I get the following error:

Quote

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/www/dxportal.awardspace.com/index.php:10) in /home/www/dxportal.awardspace.com/index.php on line 40

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/dxportal.awardspace.com/index.php:10) in /home/www/dxportal.awardspace.com/index.php on line 40

Any help to get this fixed would be greatly appreciated.

Edited by Trix06, 01 October 2006 - 02:23 AM.


#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 01 October 2006 - 04:51 AM

make sure that the session_start(); is at the top of each page and nothing is being echoed out before that.

Matt

#3 Trix06

    Young Padawan

  • Members
  • Pip
  • 292 posts
  • Gender:Male
  • Location:NSW Australia
  • Interests:Web Design &amp; Development, Graphic Design, Programming, Networking, Girls, The Beach, Amatuer Radio Communications and more.

Posted 01 October 2006 - 05:12 AM

Thanks! It worked, much appreciated. Anything I can do for you???

#4 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 01 October 2006 - 05:33 AM

no worries, don't need anything thanks.

Matt

#5 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 01 October 2006 - 03:29 PM

or you could just put <? ob_start(); ?> at the top of your page, that will fix the problem.

#6 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 01 October 2006 - 03:34 PM

Very true Chris but in this case where the function can be easily moved to the top without any complications, it's better to do so instead of calling another function to get around it :)

#7 Chris.

    Young Padawan

  • Members
  • Pip
  • 129 posts
  • Gender:Male

Posted 01 October 2006 - 05:07 PM

:) lol, okay. I always use ob_start(); especially when i integrate something intoo a layout

Edited by Chris., 01 October 2006 - 05:08 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users