Glenskie Posted September 20, 2011 Share Posted September 20, 2011 it displays is online no matter what! please help me! here is the login.php where the session is started . login.php <?php // Start Session to enable creating the session variables below when they log in session_start(); // Force script errors and warnings to show on page in case php.ini file is set to not display them error_reporting(E_ALL); ini_set('display_errors', '1'); //----------------------------------------------------------------------------------------------------------------------------------- include 'scripts/connect_to_mysql.php'; // Connect to the database // Initialize some vars $errorMsg = ''; $email = ''; $pass = ''; $remember = ''; if (isset($_POST['email'])) { $email = $_POST['email']; $pass = $_POST['pass']; if (isset($_POST['remember'])) { $remember = $_POST['remember']; } $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); // error handling conditional checks go here if ((!$email) || (!$pass)) { $errorMsg = '<font color="red">Please fill in both fields</font>'; } else { // Error handling is complete so process the info if no errors $email = mysql_real_escape_string($email); // After we connect, we secure the string before adding to query //$pass = mysql_real_escape_string($pass); // After we connect, we secure the string before adding to query $pass = md5($pass); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE email='$email' AND password='$pass' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Pleae note: Adam removed all of the session_register() functions cuz they were deprecated and // he made the scripts to where they operate universally the same on all modern PHP versions(PHP 4.0 thru 5.3+) // Create session var for their raw id $id = $row["id"]; $_SESSION['id'] = $id; // Create the idx session var $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id"); // Create session var for their username $username = $row["username"]; $_SESSION['username'] = $username; //THIS IS WHERE I EDITED THE SESSION TO SAY IF THERE LOGGED IN OR NOT $_SESSION['logedin'] = $_POST['email']; mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$id'"); mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); // THIS WAS JUST A TEST BUT WONT UPDATE UNTILL THEY LOGOUT } // close while // Remember Me Section if($remember == "yes"){ $encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id"); setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: /socialtscripts/home.php?test=$id"); exit(); } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "<h3><font color='red'>Email/Password invalid<br /></font></h3><a href='forgot_pass.php'>Forgot password?</a><div align='right'> <br> Forget to activate you account?</div>"; } } // Close else after error checks } //Close if (isset ($_POST['uname'])){ ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link href="style/main.css" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.4.2.js" type="text/javascript"></script> <title>Log In</title> <title>Login Page</title> <style type="text/css"> #stage { top: 0px; left: 0px; z-index: 100; } .stage { position: absolute; top: 0; left: 0; width: 100%; min-width: 900px; height: 1359px; overflow: hidden; } #bg { background: #aedfe5 url(images/sky1.png) 0 0 repeat-x; } #clouds { background: transparent url(images/cloud.png) 305px 10px repeat-x; } #sun { background: url(images/land_sun.gif)0 0 no-repeat; } #hillbottom { background: url(images/hill2.png)0 1270px repeat-x; } </style> <link rel="stylesheet" type="text/css" href="css/loginstyle.css" /></head> <body> <!-- IE6 fixes are found in styles/ie6.css --> <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/ie6.css" /><![endif]--> <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="js/jquery-ui-1.7.2.spritely.custom.min.js" type="text/javascript"></script> <script src="js/jquery.spritely-0.5.js" type="text/javascript"></script> <script type="text/javascript"> (function($) { $(document).ready(function() { var direction = 'left'; $('#clouds').pan({fps: 40, speed: 0.5, dir: direction, depth: 10}); }); })(jQuery); </script><div id="bg" class="stage"></div> <div id="container"> <div id="sun" class="stage"></div> <div id="clouds" class="stage"> <div id="stage" class="stage"> <body> <div id="behindform"> <form id="signinform" action="login.php" method="post" enctype="multipart/form-data" name="signinform"> <fieldset> <legend>Log in</legend> <label for="login">Email</label> <input type="text" id="email" name="email" /> <div class="clear"></div> <label for="password">Password</label> <input type="password" id="password" name="pass" /> <div class="clear"></div> <label for="remember_me" style="padding: 0;">Remember me?</label> <input type="checkbox" id="remember" style="position: relative; top: 3px; margin: 0; " name="remember"/ value="yes" checked="checked"> <div class="clear"></div> <br /> <input type="submit" style="margin: -20px 0 0 287px;" class="button" name="commit" value="Sign In"/> </fieldset><?php print "$errorMsg"; ?> </form> </div> </div> </div><div id="hillbottom" class="stage"> </div> </body> </html> and then this is the profile.php where i see if there online , i could only put sertian areas , script is too big profile.php <?php //on top of the page where it checks the session and updates the time // This updates the database correctly if( isset($_SESSION['logedin']) ) { mysql_query("UPDATE myMembers SET last_activity=now() WHERE id='$logOptions_id'"); // this is where it selects the users id but it wont work , it says online for every user! $age= 60; if( isset($_SESSION['logedin']) ) { $q = mysql_query('SELECT id=`$logOptions_id`, DATE_FORMAT(`last_activity`,"%a, %b %e %T") as `last_activity`,UNIX_TIMESTAMP(`last_activity`) as `last_activity_stamp`FROM `mymembers`WHERE `$logOptions_id` <> "'.($_SESSION['logedin']).'"'); $isonlinecheck = mysql_query($q); if ($isonlinecheck ="last_activity_stamp" + $age < time()){ $isonline = "is <font color='green'>online!</font>";} else { $online = "is<font color='red'> offline!</font>"; } } ?> PLEASE HELP ME Quote Link to comment https://forums.phpfreaks.com/topic/247555-user-is-online-help-please/ Share on other sites More sharing options...
WebStyles Posted September 21, 2011 Share Posted September 21, 2011 Just a though: I would do it the other way around... if users are logged in, I wouldn't show last activity time (since they're online, I assume they're last activity was only seconds or minutes ago), on the otherhand, if they're offline, then I would want to know when their last activity was...(how many days, minutes, hours ago) the easiest way to keep track is to store a unix timestamp directly in the database (Avoids having to do all the conversions). personally I also use a field called `online` (varchar 1) that can have values 'Y' or 'N', speeds up queries, allows me to get online users without grabbing a timestamp, also allows me to see who's online when I'm accessing the database directly (i.e. through phpMyAdmin, or something) Quote Link to comment https://forums.phpfreaks.com/topic/247555-user-is-online-help-please/#findComment-1271309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.