Jump to content

online offline help


redarrow

Recommended Posts

 

I am trying to create a online and off line user plug in.

 

for some reason it not working correctly like the set cookie does not work.

 

can you kindly give it a quick once over.

 

any errors i am so sorry.

 

<?php session_start();


$db=mysql_connect("localhost","username","password");
$db_res=mysql_select_db("onlin_offline_users",$db)or die("Databse connection error\n".mysql_error());

$sql="CREATE DATABASE online_offline_users";

$res=mysql_query($sql)or die("Create database error\n".mysql_error());

$sql2="USE online_offline_users";

$res2=mysql_query($sql2)or die("Use database error\n".mysql_error());

$sql3="CREATE TABLE online_offline(
online_offline_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
users_id INT NOT NULL,
online_timestamp int(20) NOT NULL,
users_ip INT(20) NOT NULL)";

$res3=mysql_query($sql3)or die("Create online_offline table error\n".mysql_error());


$sql4="SELECT * FROM users WHERE id={$_SESSION['id']} AND activated='yes'";

$res4=mysql_query($sq4)or die("Select users error\n".mysql_error());


if(mysql_num_rows($res4)){

$timestamp=time();

$users_ip=$_SERVER['REMOTE_ADDR'];

$sql5="UPDATE online_offline SET online_offline_id='".mysql_real_escape_string($_SESSION['id'])."',
online_timestamp='".mysql_real_escape_string($_POST['timestamp'])."',
users_ip='".mysql_real_escape_string($_POST['users_ip'])."' WHERE id='{$_SESSION['id']}'";


$res5=mysql_query($sq5)or die("Update online offline error\n".mysql_error());
}

$sql6="SELECT * FROM online_offline";

$res6=mysql_query($sq6)or die("SELECT online offline error\n".mysql_error());

while($online_data=mysql_fetch_assoc($res6)){

$_SESSION['online_offline_id']=$online_data['online_offline_id'];


setcookie("online",$_SESSION['online_offline_id'],$online_data['online_timestamp']+1800);


if($_COOKIE['online']){

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is online!";

}else{

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is NOT online! ";
}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/
Share on other sites

The code from the top off my head, and it does not seem to work, that why i need help,

 

Maybe i am completely codding it all wrong don't no.

 

i wrote the code hoping it would just work.

 

i need guidance on creating the code.

 

am i,  on the wright tracks with the current code?

 

is this code even valid as a properly written code.

 

<?php
$sql6="SELECT * FROM online_offline";

$res6=mysql_query($sq6)or die("SELECT online offline error\n".mysql_error());

while($online_data=mysql_fetch_assoc($res6)){

   $_SESSION['online_offline_id']=$online_data['online_offline_id'];
   

   setcookie("online",$_SESSION['online_offline_id'],$online_data['online_timestamp']+1800);
   
   
   if($_COOKIE['online']){
      
      echo "user with the id of:\n {$_SESSION['online_offline_id']} IS online!";
   
   }else{
      
      echo "user with the id of:\n {$_SESSION['online_offline_id']} is NOT online! ";
   }
   
}

?>

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/#findComment-787415
Share on other sites

 

advance thank you.

 

 

I have tested my code, and it says all user's are online,

 

What i want to no,

is when the half hour 1800 seconds is up,

 

will the cookie die and say there offline.

 

<?php

$_SESSION['podcast_user_id']=24;


$sql4="SELECT * FROM podcast_users WHERE podcast_user_id='{$_SESSION['podcast_user_id']}' AND podcast_activated='yes'";

$res4=mysql_query($sql4)or die("Select users error\n".mysql_error());


if(mysql_num_rows($res4)){

  $timestamp=time();

$users_ip=$_SERVER['REMOTE_ADDR'];

$sql5="INSERT INTO online_offline(users_id,online_timestamp,users_ip)VALUES('".$_SESSION['podcast_user_id']."','".mysql_real_escape_string($timestamp)."','".mysql_real_escape_string($users_ip)."')";



$res5=mysql_query($sql5)or die("Update online offline error\n".mysql_error());
}

$sql6="SELECT * FROM online_offline";

$res6=mysql_query($sql6)or die("SELECT online offline error\n".mysql_error());

while($online_data=mysql_fetch_assoc($res6)){

$_SESSION['online_offline_id']=$online_data['online_offline_id'];


setcookie("online",$online_data['online_timestamp']+1800);


if($_COOKIE['online']){

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is online!";

}else{

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is NOT online! ";
}

}


?>

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/#findComment-787433
Share on other sites

 

 

how do you kill the cookie that are not online.

 

so near to complete this.

 

i no a code is placed on the else from the if but what ....

 

<?php
$_SESSION['podcast_user_id']=24;


$sql4="SELECT * FROM podcast_users WHERE podcast_user_id='{$_SESSION['podcast_user_id']}' AND podcast_activated='yes'";

$res4=mysql_query($sql4)or die("Select users error\n".mysql_error());


if(mysql_num_rows($res4)){

  $timestamp=time();

$users_ip=$_SERVER['REMOTE_ADDR'];

$sql5="INSERT INTO online_offline(users_id,online_timestamp,users_ip)VALUES('".$_SESSION['podcast_user_id']."','".mysql_real_escape_string($timestamp)."','".mysql_real_escape_string($users_ip)."')";



$res5=mysql_query($sql5)or die("Update online offline error\n".mysql_error());
}

$sql6="SELECT * FROM online_offline";

$res6=mysql_query($sql6)or die("SELECT online offline error\n".mysql_error());

while($online_data=mysql_fetch_assoc($res6)){

$_SESSION['online_offline_id']=$online_data['online_offline_id'];


setcookie("online",$_SESSION['online_offline_id'],$online_data['online_timestamp']+60);

if(isset($_COOKIE['online'])){

  echo "user with the id of:\n {$_SESSION['online_offline_id']} is online! <br>";

	}else{

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is NOT online!<br> ";
}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/#findComment-787447
Share on other sites

 

This should work.

 

 

should show all users online and off line via the cookies.

 

what have i done wrong please.

 

as you can see if the cookie is set then there online,

 

if there off line then kill the cookie.

 

where am i going wrong please.

 

<?php session_start();

$_SESSION['podcast_user_id']=24;


$sql4="SELECT * FROM podcast_users WHERE podcast_user_id='{$_SESSION['podcast_user_id']}' AND podcast_activated='yes'";

$res4=mysql_query($sql4)or die("Select users error\n".mysql_error());


if(mysql_num_rows($res4)){

  $timestamp=time();

$users_ip=$_SERVER['REMOTE_ADDR'];

$sql5="INSERT INTO online_offline(users_id,online_timestamp,users_ip)VALUES('".$_SESSION['podcast_user_id']."','".mysql_real_escape_string($timestamp)."','".mysql_real_escape_string($users_ip)."')";



$res5=mysql_query($sql5)or die("Update online offline error\n".mysql_error());
}

$sql6="SELECT * FROM online_offline";

$res6=mysql_query($sql6)or die("SELECT online offline error\n".mysql_error());

while($online_data=mysql_fetch_assoc($res6)){

$_SESSION['online_offline_id']=$online_data['online_offline_id'];


setcookie("online",$_SESSION['online_offline_id'],$online_data['online_timestamp']+60);

if(isset($_COOKIE['online'])){

  echo "user with the id of:\n {$_SESSION['online_offline_id']} is online! <br>";

	}else{

		setcookie( "online", $_SESSION['online_offline_id'], $online_data['online_timestamp']-60 );

	echo "user with the id of:\n {$_SESSION['online_offline_id']} is NOT online!<br> ";
}


}

?>

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/#findComment-787452
Share on other sites

might have to do it this way what a shame,

 

was enjoying my cookie times.

 

   <?
$five_minutes_ago=date()-300;

$result=mysql_query("select user_name from users where lastvisit > '$five_minutes_ago'");
?> 

 

   <?
// insert something like this at the top of each page
// the 'lastvisit' field in the db is an int(14)
$now=date();

// this assumes that $user_id is the unique identifier
// and exists in this php script already
$result=mysql_query("update users set lastvisit='$now' where user_id='$user_id'");
?> 

Link to comment
https://forums.phpfreaks.com/topic/149930-online-offline-help/#findComment-787463
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.