06-25-2019, 05:30 PM
|
|
Videochat Solutions
Industry Role:
Join Date: Aug 2004
Location: Canada
Posts: 49,244
|
Quote:
Originally Posted by zerovic
Here's something I just wrote real fast... it's not the best solution, however, it'll do the job and you'll get the idea ;)
Code:
<?php
//make sure you are connected to your database!
if(isset($_GET['username'])) {
$username = $_GET['username'];
$current_date = date('Y-m-d H:i:s');
//update the database with the current date/time
//for example
//mysql_query("update `users` set `last_seen` = '$current_date' where `username` = '$username'");
}
?>
<head>
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<base href="https://gfy.com/" /><!--[if IE]></base><![endif]-->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var username = 'username';
UpdateUserTime = setInterval(function() {
$.ajax({
url: "http://localhost/2MuchMark.php?username=" + username,
cache: false,
success: function (html) {
$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
}
});
}, 5000); // the interval you want to update the current time / date.
});
</script>
</head>
<body>
<div id="foo"></div>
</body>
Basically, you have the current username stored as a jquery variable which is sent to the php script every 5 seconds which updates the users last seen time / date.
Let me know if it works for you, or you have any questions.
ps. you are not limited to only date/time. you can store anything such as the current page if you want. for this I'd suggest using POST instead of GET, but everything is the same.
Simply change the type of the request to POST and define the data you are sending with.
Code:
UpdateUserTime = setInterval(function() {
$.ajax({
type: "POST",
data: 'username=' + user + '¤t_page=' + current_page,
url: "http://localhost/2MuchMark.php",
cache: false,
success: function (html) {
$('#foo').append('User time/date updated.<br />'); // you can leave this empty, it's just to see if the request was successful.
}
});
}, 5000);
Cheers,
z
|
Thanks! Will try that.
Quote:
Originally Posted by Sarn
Google Analytics Real Time report.
|
Thanks Sarn but that's not what I'm looking for. What I want is for my own program to know which users are actually logged-in in real time, and when they click out of the site. But thanks though I appreciate the suggestion.
__________________
Custom Coding | Videochat Solutions | Age Verification | IT Help & Support
www.2Much.net
|
|
|