|
Joined: Nov 2003
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Nov 2003
Posts: 4 |
is there a way (code, etc) to show an online status image on our web page while we ol using registered nick ? i've been searching for this around, but couldn't find any clue yet. anyone can help ? thx
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
You can either have mirc make a webpage and upload it on a regular basis (either hourly, every 5 minutes, or whatever interval you choose), or if you have access to perl, php, or cgi--you can have mirc query the server and tell it you are online..
-KingTomato
|
|
|
|
Joined: Nov 2003
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Nov 2003
Posts: 4 |
i have access to PHP. but as a newbie, i still can't figure the codes to show an online status image in my web page to tell the visitor that i'm online on mirc with my registered nick. can u help me King
|
|
|
|
Joined: Jul 2003
Posts: 742
Hoopy frood
|
Hoopy frood
Joined: Jul 2003
Posts: 742 |
help me too please?  i have php also an additional note: maybe if you can create this you can make one for aim icq and msn messengers? 
Last edited by MTec89; 05/11/03 01:10 PM.
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
this *should* be a quick demo.. im at school, so I don't have the mneans of testing it, but I will write something up.. This will be what the PHP looks like (I'll assume you know a lil about php. If not, just handle the variable I provide...) I will also be using mysql, but you can use a file just as easy. The onlything is, mysql qould be easier for multiple users. Again, untested but this is the general idea..
<html>
<head>
<title>Online Status</title>
</head>
<body>
<?
$mysql_user = ""; // username for mysql database
$mysql_pass = ""; // password to database
$mysql_host = "localhost"; // hostname to database
$mysql_db = ""; // database name
$mysql_table = "usrstats"; // table containing the user info
@$db = mysql_connect($mysql_user, $mysql_pass, $mysql_host);
if ($db)
{
mysql_select($mysql_db) or die("Unable to select database");
// check if the ?loginname=<name>&status=<status> was set.
if (isset($_get["loginname"]) && isset($_GET["status"]))
{
// Login the user into the database
$query = "SELECT * FROM $mysql_table WHERE name='$_GET[loginname]';";
$result = mysql_query($query);
// there is already an entry, so we update
if (mysql_num_rows($result) > 0) {
$query = "INSERT INTO $mysql_table VALUES (NULL, '$_GET[loginname]', '$_GET[status]') WHERE name='$_GET[loginname]';";
}
// need to add them into the database
else
{
$query = "UPDATE $mysql_table SET status='$_GET[status]' WHERE name='$_GET[loginname]';";
}
$result = mysql_query($query);
if ($result)
{
echo "$_GET[loginname] status set to: $_GET[status]";
}
else
{
echo "Unable to set $_GET[loginname]'s status";
}
}
}
else
echo "Unable to query the database";
?>
</body>
</html>
Name this to online.php, or change the name in the SOCKOPEN event also. This might be useful to your mysql table...
CREATE TABLE usrstats
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name CHAR[50],
status CHAR[8] = 'Offline',
INDEX(id)
);
INSERT INTO usrstats VALUES (NULL, '[color:red]YourName[/color]', 'Offline');
(Please excuse my sql definition, it has been a while for me. Wheni get home, i'll verify a working version. mIRC Code...
; usage: /setStatus <user> <online/offline>
; example:
; on *:CONNECT: { /setstatus $me online }
; on *:DISCONNECT: { /setStatus $me offline }
alias setStatus {
var %host = [color:red]Website.com[/color]
/sockopen usrstats 80
/sockmark %host $+ , $+ $1-
}
on 1:SOCKOPEN:usrstats: {
; this is the path to your file. It's going to
; be the link to the file, less the domain
; ex:
; http://www.mywebsite.com[color:red]/folder/online.php[/color]
; (Exclude the http:// part)
var %path = [color:red]/online.php[/color]
;
;
var %mark = $sock($sockname).mark
var %host = $gettok(%mark, 1, 44)
var %parm = $gettok(%mark, 2, 44)
if ($sockerr) var %a = $input(Unable to set the status for $gettok(%parm, 1, 32), 1, 32), o, Error)
else {
var %loginname = $gettok(%parm, 1, 32)
var %status = $gettok(%parm, 2, 32)
/sockwrite -n $sockname GET $+(%path,?loginname=,%loginname,&,status=,%status) HTTP/1.0
/sockwrite -n $sockname Host: %host
/sockwrite -n $sockname $crlf
/set -u10 %usrstats.header 1
}
if ($isfile(data.txt)) .rem data.txt
}
on 1:SOCKREAD:usrstats: {
if (%usrstats.header) /sockread 0f %header
else {
/sockread -f &data
/bwrite data.txt -1 -1 &data
}
}
on 1:SOCKCLOSE:usrstats: {
/bread data.txt 0 $file(data.txt).size &data
var %loc = $bfind(&data, 0, <body>)
var %len = $bfind(&data, 0, </body>) - %loc
/echo -a Status Outcome: $bvar(&data, %loc, %len)
}
You basically have a php page that holds the status in a mysql table. From there,you use mIRC sockets to set the status with the php get variables. From there, you can use a query like..
<?
... php code ...
$query = "SELECT * FROM $mysql_table;";
$result = mysql_query($query);
if ($result) {
$results = mysql_num_rows($result);
if ($results < 1) {
echo "No users in database";
}
else {
for ($a = 0; $a < $results; $a++)
{
$row = mysql_fetch_array($result);
echo "User: $row[loginname] - Status: $row[status]<br>\n";
}
}
}
... php code ...
?>
And if memory serves me right (and again, untested) that should loop through the database and print out something like: user: KingTomato - Status: online user: cpox - Status: Offline ...etc
-KingTomato
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
Okay, here is a working version... online.php:
; host to connect to (no http prefix)
[color:Red]alias online_host { return 127.0.0.1 }[/color]
; this is the path to your file. It's going to
; be the link to the file, less the domain
; ex:
; http://www.mywebsite.com/folder/online.php
; (Exclude the http:// part)
[color:Red]alias online_path { return /mIRC/online.php }[/color]
; in my case, i had my own webserver:
; http://127.0.0.1/mIRC/online.php was my file and path.
; -------------------------------------------------------------------------------------------------
; usage: /setStatus <user> <online/offline>
; example:
; on *:CONNECT: { /setstatus $me online }
; on *:DISCONNECT: { /setStatus $me offline }
alias setStatus {
var %host = $online_host
/sockopen usrstats %host 80
/sockmark usrstats %host $+ , $+ $1-
}
on 1:SOCKOPEN:usrstats: {
var %path = $online_path
var %mark = $sock($sockname).mark
var %host = $gettok(%mark, 1, 44)
var %parm = $gettok(%mark, 2, 44)
if ($sockerr) var %a = $input(Unable to set the status for $gettok(%parm, 1, 32), 1, 32), o, Error)
else {
var %loginname = $gettok(%parm, 1, 32)
var %status = $gettok(%parm, 2, 32)
/sockwrite -n $sockname GET $+(%path,?loginname=,%loginname,&,status=,%status) HTTP/1.0
/sockwrite -n $sockname Host: %host
/sockwrite -n $sockname $crlf
/set -u10 %usrstats.header 1
}
if ($isfile(data.txt)) .remove data.txt
}
on 1:SOCKREAD:usrstats: {
if (%usrstats.header) {
/sockread 0f %header
if (%header == $null) /unset %usrstats.header
}
else {
/sockread -f &data
/bwrite data.txt -1 -1 &data
}
}
on 1:SOCKCLOSE:usrstats: {
/bread data.txt 1 $file(data.txt).size &data
var %loc = $bfind(&data, 1, <body>) + 8
var %len = $bfind(&data, 0, </body>) - %loc
/echo -a Status Outcome: $bvar(&data, %loc, %len).text
}
; -------------------------------------------------------------------------------------------------
alias getstatus {
var %host = $online_host
/sockopen usronline %host 80
}
on 1:SOCKOPEN:usronline: {
var %host = $online_host
var %path = $online_path
if ($sockerr) var %a = $input(Unable to get the status, o, Error)
else {
/sockwrite -n $sockname GET %path HTTP/1.0
/sockwrite -n $sockname Host: %host
/sockwrite -n $sockname $crlf
/set -u10 %usronline.header 1
}
if ($isfile(data.txt)) .remove data.txt
}
on 1:SOCKREAD:usronline: {
if (%usronline.header) {
/sockread 0f %header
if (%header == $null) /unset %usronline.header
}
else {
/sockread -f &data
/bwrite data.txt -1 -1 &data
}
}
on 1:SOCKCLOSE:usronline: {
/bread data.txt 1 $file(data.txt).size &data
var %loc = $bfind(&data, 1, <body>) + 8
var %len = $bfind(&data, 0, </body>) - %loc
/echo -a Status Outcome: $bvar(&data, %loc, %len).text
}
use the following aliases: /setstatus <name> <online/offline> /getstatus online.php:
<html>
<head>
<title>Online Status</title>
</head>
<body>
<?
[color:Red]$mysql_user = ""; // username for mysql database
$mysql_pass = ""; // password to database
$mysql_host = "localhost"; // hostname to database
$mysql_db = "Demo"; // database name[/color]
[color:blue]$mysql_table = "usrstats"; // table containing the user info (This one shouldn't have to be changed)[/color]
@$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
if ($db)
{
$select = mysql_select_db($mysql_db) or die("Unable to select database");
// check if the ?loginname=<name>&status=<status> was set.
if (isset($_GET["loginname"]) && isset($_GET["status"]))
{
// Login the user into the database
$query = "SELECT * FROM $mysql_table WHERE uname='$_GET[loginname]';";
$result = mysql_query($query);
// there is already an entry, so we update
if (mysql_num_rows($result) == 0) {
$query = "INSERT INTO $mysql_table VALUES (NULL, '$_GET[loginname]', '$_GET[status]');";
}
// need to add them into the database
else
{
$query = "UPDATE $mysql_table SET status='$_GET[status]' WHERE uname='$_GET[loginname]';";
}
$result = mysql_query($query);
if ($result)
{
echo "$_GET[loginname] status set to: $_GET[status]";
}
else
{
echo "Unable to set $_GET[loginname]'s status";
}
}
// nothing passed, just list results
else
{
$Online = "Online: ";
$query = "SELECT * FROM $mysql_table WHERE status='online';";
$result = mysql_query($query);
$results = mysql_num_rows($result);
for ($a = 0; $a < $results; $a++)
{
$row = mysql_fetch_array($result);
$Online .= ($a != 0?", ":"").$row[uname];
}
echo ($Online == "Online: "?"No users online":$Online);
}
}
else
echo "Unable to query the database:<br>\n".mysql_error();;
?>
</body>
</html>
and finally the sql file:
CREATE TABLE usrstats
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
uname CHAR(50),
status CHAR(8),
INDEX(id)
);
INSERT INTO usrstats VALUES (NULL, '[color:red]YourName[/color]', 'Offline');
Change the red portions to your own settings. That should work out fine, as it does on mine. I have it query, and set fine.
-KingTomato
|
|
|
|
Joined: Jul 2003
Posts: 742
Hoopy frood
|
Hoopy frood
Joined: Jul 2003
Posts: 742 |
EDit: does your method not produce a security threat???? i mean your setting status via stuff retreaved from the url variables...right? seriously, dude your leet. thanks alot  how can i make this info an image? (one user, myself only of course) kind of like the project dolphin one, except 88x31 pixels instead also, how can i display a table of users with their status online or offline? (a seperapte page than the image one i have requested.)
Last edited by MTec89; 05/11/03 08:17 PM.
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
I was actually going to do that next. I was thinking about how you could impliment it into a webpage, and i came to a conclusion. if I make it into a function, you can call it easily. All you;d do is at the top of ur site, use:
include("online.php");
then call something like showOnline(); as well is perhaps isOnline("user");
Gimme an hour or so, and I'll have it >:D
-KingTomato
|
|
|
|
Joined: Nov 2003
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Nov 2003
Posts: 4 |
you deserve my big hug, King  i just jump to this board this afternoon and there's bunch of codes i can try of. i still not test it yet, but once again, u deserve my hugs  i'll wait for your next code to show an online/offline image. going to try ur codes now. thx 'lot my friend
|
|
|
|
Joined: Nov 2003
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Nov 2003
Posts: 4 |
wait, is there 2 online.php file should i upload to server? 1st one is online.php file contained this code: alias online_host { return 127.0.0.1 } ......... ......... the other is online.php file contained this code: <html> <head> <title>Online Status</title> </head> <body> <? $mysql_user = ""; // username for mysql database $mysql_pass = ""; // password to database .......... .......... i believed i was wrong, pls help thx
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
I Have PM'd you a link to my personal apache server, thast has the files and a working demo. Just upload those to the directory you choose, and all should be well. I made decent comments in the code, so you can follow along and should be able to make use of the class. There is also a file called examples.php that has several examples of how things work. Just look through the source, and see how its used--then plug it into your own use. >:S
If anyone else would like th efile, please feel free to PM me. I would release the link, but I have enough search engines that query my ip a day--don't need more.
-KingTomato
|
|
|
|
|