Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lett visitors see if i'm online 1

Status
Not open for further replies.

Mikeb1970

Technical User
Nov 14, 2003
101
BE
Hello,

I want an online or offline message apear on my website so that visitors know if i am online or not.
Not sure if this can be done with dreamweaver, don't have a clue on how to try to make this, so all help would be very welcome

Greetings

Biermans Mike
 
Online, or off-line of what? what establishes your status?

Dreamweaver, is just a tool, it might not have any script in its library that can do it, but depending on how you wanted to work creating one can be very simple. What server-side language are you using? Again how would it check for your status?

How exactly does it help your visitors to know you are online? Can you explain a bit more?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Haven't thought about any server-side language, basiccaly i just wanna log in on a webpage and then lett it display in my index.html page in green text that i'm online. What server-side language would help me do this ? like i said any suggestions are welcome


Thank you

Mike
 
Any server side side language will help you do this, the question here would be what does your webhost support?

What you want to do is fairly simple in any language, but we need to know which one your host supports.










----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I have contacted my webhost and got a list from them containing the languages they support
PHP,ASP by Sun Chili,Javascript,CSS,DOMXML,HTML/XHTML and server side includes XML

Hope this is enough info for you


Mike
 
We can use PHP but you'll have to change your index page into a PHP file for this to work. so if your index page is index.html it will need to be index.php.

Since you have no DB or anything, we can store your status in a text file so that it can be accessed when users open your website.

First create a page called login.php and copy this into it
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<?PHP
$filename="status.log";
if(!is_file($filename)){
$h=fopen($filename,"x");
$stfile="loggedout|Offline|Now and maybe later also";
$f=fwrite($h,$stfile);
fclose($h);
}

if(isset($_POST['log'])){
$handle=fopen($filename,"w+");

if(isset($_POST['login'])){
echo "Loggin in...";
$d="Today at " . date("g:i:s a");
$stfile="loggedin|Online|" . $d;
sleep(1);
$f=fwrite($handle,$stfile);
fclose($handle);
}

if(isset($_POST['logout'])){
$stfile="loggedout|Offline|Now and maybe later also";
$f=fwrite($handle,$stfile);
fclose($handle);

}

}

$handle=fopen($filename,"r+");
$cont=fread($handle,filesize($filename));
$st=explode("|",$cont);
$stid=$st[0];
$status=$st[1] . " as of " . $st[2]; 


fclose($handle);

?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Basic insert to db</title>
<style>
#loginbox{
background-color:#e2e0d8;
border:1px solid black;
margin-left:auto;
margin-right:auto;
width:200px;
height:110px;
}

#buttons{
width:100%;
padding-left:auto;
padding-right:auto;
text-align:center;
border-bottom: 2px inset;
}
#statusbox{
width:100%;
padding-right:auto;
padding-left:auto;
text-align:center;
}

#statlabel{
font-weight:bold;
padding-left:5px;
}

#loggedin{
background-color:black;
color:#40ff40;
padding-left:2px;
border:1px solid red;
}
#loggedout{
background-color:black;
color:#ff4040;
padding-left:2px;
border:1px solid red;
}


</style>
</head>
<body>
<form action=login.php method=POST>
<div id="loginbox">
<div id="buttons">
<input type=submit name="login" value="Login">
<input type=submit name="logout" value="Logout">
<input type=hidden name="log" value="do">
</div>
<div id="statusbox"><span id="statlabel">Status:</span><div id="<?echo $stid;?>"><?echo $status;?></div></div>
</div>
</form>
</body>
</html>

Then in whichever page you wish to show your status copy this:

Code:
<?PHP
function get_status(){
$filename="status.log";
$handle=fopen($filename,"r+");
$cont=fread($handle,filesize($filename));
$st=explode("|",$cont);
$stid=$st[0];
$status=$st[1] . " as of " . $st[2]; 
fclose($handle);
echo $status;
}
?> //at the top of your page.

and place this wherever in your page you want to show the status:

Code:
<?PHP get_status(); ?>

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
This works great Vacunita,
thnx a million for the code, it got me intressted in PHP
so i will learn PHP to, ;-)

With regards

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top