Jump to content

Ashoar

Members
  • Posts

    214
  • Joined

  • Last visited

    Never

About Ashoar

  • Birthday 09/24/1990

Contact Methods

  • Website URL
    http://www.creative-design-forum.com

Profile Information

  • Gender
    Male
  • Location
    Australia

Ashoar's Achievements

Member

Member (2/5)

0

Reputation

  1. Update: It works and logs the user in correctly without removing them right away, the only problem is that it won't remove them after 15 minutes unless they try and request a page. So the user can sit on a single page for 15 minutes or closes the browser, but it won't remove them from the online table until they request a new page after 15 minutes.
  2. Thank you for the reply jcbones. So far that is working, i see where my error was. At the moment it now logs the user in and doesn't automatically remove them. I will let it sit for 15 minutes and see what happens and also close the browser for 15 minutes after to see if it works. Will updates once i see the results. Also want to check this is correct, shouldnt the last online time in the database show an actual time and not a string of numbers? Currently have this in the database: ID: 5 Username: Jye. Lastonline: 1270511983
  3. Yes that seems to be correct.
  4. I have moved further with this and just about have it working. Currently running into a wall however. When a user logs in they automatically get logged out as soon as the new page loads after hitting log in. The reason for this is because of the check that runs on each page to see if the user has been active within a 15 minute period. Databae: id int(11) NOT NULL auto_increment, Username text NOT NULL, lastonline bigint(20) NOT NULL default '0', PRIMARY KEY (id) The login: if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; $time = time(); $insertuser="INSERT INTO online(Username,lastonline) values('$username','$time')"; mysql_query($insertuser) or die("Could not login insert user"); header("Location: index.php"); } else { header("Location: l_error.php"); I'm pretty sure that is working correctly and adding the time they logged in. This is the script that runs each page: session_start(); $lastonline = time(); if ($_SESSION['lastonline'] <= (time() - 900)) // 900 = 15 minutes (60x15) { $username = $_SESSION['s_username']; $query = "DELETE FROM online WHERE username = '".mysql_real_escape_string($_SESSION['s_username'])."';"; $result = mysql_query($query); $_SESSION['s_logged_n'] = ''; $_SESSION['s_name'] = ''; $_SESSION['s_username'] = ''; session_destroy(); } else { $username = $_SESSION['s_username']; $_SESSION['lastonline'] = time(); $query = "INSERT INTO online(Username, lastonline) VALUES('${lastonline}')"; $updateonline="Update online set username='$username',lastonline='$lastonline'"; mysql_query($updateonline) or die("Could not update online"); } It seems the script is skipping the original IF statement to check the time and just destroys the session as soon as the user logs in. Is their anything missing in either of those scripts that may be causing the problem?
  5. Still having trouble working this out
  6. I will be looking in to fixing that Ignace, just looking at getting this going first. Any further suggestions at setting this up?
  7. I am aware of the numerous ones online for general visitor count but my original question was more so aimed to implementing one within my current script which is the part i was having trouble with.
  8. Thanks for the reply. That is the part i know, i'm just stumped as to how i can apply it or add it to the current code i have there. As i said above i am dreadful when it comes to sessions considering their simplicity. Any chance of showing how it can be implemented there?
  9. Had a search of the forum but couldn't really find much that related to much to my desired result. Currently when a user logs in, once the system has authenticated them it will then log their details into an "online" database table like so: if($row['Activated'] > 0) { $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['s_name'] = $row['Name']; $insertuser="INSERT INTO online(Username) values('$username')"; mysql_query($insertuser) or die("Could not login insert user"); header("Location: index.php"); } else { Then in my information center i just pull all results from the "online" table to display the users online. Now off course by using this method the only possible way a name can be removed from the database is if the user manually hits the logout button where i then run: $username = $_SESSION['s_username']; $query = "DELETE FROM online WHERE username = '".mysql_real_escape_string($_SESSION['s_username'])."';"; $result = mysql_query($query); $_SESSION['s_logged_n'] = ''; $_SESSION['s_name'] = ''; $_SESSION['s_username'] = ''; session_destroy(); If a user just closes the browser without logging out they will stay logged in for the default php session length before the session is destroyed. The problem here is that it won't remove them from the online table meaning they will always be displayed in users online. When they login next their name will then appear 2 times in users online and only get taken off if they actually click logout. Now i can always add: ini_set(’session.gc_maxlifetime’, ‘0′); Which would mean the session would not end unless they click log out regardless of whether they leave or not. Now i am absolutely hopeless with sessions with timestamps, so does anyone have some insight as to how i could implement it into the current code and the code of each page for the timestamps?
  10. Nah i cannot do it like that. The current ORDER BY f.forum_id asc") orders the actual boards on the main page. If i change that the boards starts changing around. I thought i would be able to do this: MAX(p.title) AS title ORDER by lastreplied asc, But that just gives errors.
  11. I have run into a little problem. I have a section of code that included a MYSQL query. This piece of code fetches and displays all the forum boards on the main page plus the posts, threads and last post for each board. This is the code: $boards = mysql_query("SELECT f.forum_name, f.forum_desc, f.board, COUNT(DISTINCT p.post) AS threads, MAX(p.showtime) AS showtime, MAX(p.title) AS title, SUM(p.numreplies) AS reply FROM forums AS f LEFT JOIN post_reply AS p ON p.board=f.board GROUP BY f.forum_name, f.forum_desc, f.board ORDER BY f.forum_id asc") or die(mysql_error()); $boards2 = mysql_num_rows($boards); for($count = 1; $count <= $boards2; $count++) { $board = mysql_fetch_array($boards); print "<tr class='mainrow'><td><center><img src='/images/onoff.jpg'></center></td><td><A href='board.php?board=".$board['board']."'>".$board['forum_name']."</a><p>".$board['forum_desc']."</p></td><td>On ".$board['showtime']."<br><br><A href='member_profile.php?post=$board[title]'>$board[title]</a></td><td><center>".$board['threads']."</center></td><td><center>".$board['reply']."</center></td></tr>"; } print "</table>"; ?> The problem is that i cannot get the last post/reply of each board. The last reply, in this code is "Title" in the MYSQL query. I am using MAX in the MYSQL query but it doesn't seem to be fetching the very last entry from the selected row. Would their be a way to change this through php to grab the very last entry in that row or is their an alternate to MAX? Or is their a way to change this code, so that i can order, only the title, by lastrepliedto? Thanks.
  12. Ashoar

    Online

    Yes you are still logged in regardless of the page you are on, i have the session start in the header of each page, which is also where i was placing the time stamps.
  13. Ashoar

    Online

    Back to first page. Could some one show me exactly how this could be done using timestamps? I can't manage to get anything working using them.
  14. Ashoar

    Online

    I have checked some tutorials but have been unable to correctly work it. Could you show me the correct method of doing so.
  15. You need to set the username of the people logging in as well as setting the cookie and it may work. $username = $_SESSION['username']; Where username would be the name of the username session you set when a user logs in. Then every time a user does something or sets something, save it to the mysql table where the username row in the table = the username variable.
×
×
  • 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.