Newest and total members

Posted on Wednesday 4th July 2007 at 09:09 PM
dtnet
dtnet's Avatar
When I log out, and press ctrl + r (f5), the "total members" says that there are 2 members at the site. But, that second person is actually the first member that have ever registered, its just a copy. Thats happend all the time. When I'm logging out the stat are adding one more member (again only a copy of the 1. member.)

logout.php
PHP Code
  1. <?php
  2. session_start(); //allows session
  3. include "config.php";
  4. echo "<center>";
  5. //checks there trying to logout
  6. if(isset($_GET['logout'])){
  7. //deletes the sessions
  8. unset($_SESSION['id']);
  9. unset($_SESSION['password']);
  10. //loggedout message
  11. echo "You are now logged out.";
  12. }
  13. echo "<center>";
  14. ?>


online.php
PHP Code
  1. <?php
  2. include("config.php");
  3.  
  4. //Query database & Counts the rows in the members database
  5. $count = mysql_num_rows(mysql_query('SELECT * FROM `members`'));
  6.  
  7. echo $count; //Displays the total members
  8.  
  9. $new = mysql_fetch_array(mysql_query("SELECT * FROM `members` ORDER BY `id` DESC LIMIT 0, 1")); //Gets the newest member
  10. echo "Newest User: " . $new[username]; //Displays the newest member
  11. ?>
Posted on Wednesday 4th July 2007 at 10:41 PM
SkillMaster
SkillMaster's Avatar
Can you explain your problem a it more
Posted on Thursday 5th July 2007 at 09:50 AM
dtnet
dtnet's Avatar
sure.

https://henrik.hotserv.dk/members.php

As you can see in the link, there are many members with the same name. But, if you click on one of them, you can see that they are all the same member.

I can log in and out without problems. But when I log out, the memberlist is adding a new copy of the member. It's also adding the new member in the database.

Now, I saw that when I log in, the memberlist is adding a new copy of the member that I log in with.
Posted on Thursday 5th July 2007 at 09:39 PM
SkillMaster
SkillMaster's Avatar
It must be your login code? post it?
Posted on Saturday 7th July 2007 at 08:35 PM
dtnet
dtnet's Avatar
PHP Code
  1. <?php
  2. session_start();
  3. require_once "config.php";
  4. if($logged[id]){
  5. echo "<h3>Velkommen $logged[username]</h3>";
  6. echo "
  7. <div><a href='editprofile.php'>Endre Profil</a><br>
  8. <a href='changepassword.php'>Bytt Passord</a><br>
  9. <a href='members.php'>Medlemmer</a><br>
  10. <a href='logout.php?logout'>Logg ut</a></div>";
  11. }
  12. else
  13. //if there trying to login
  14. if(isset($_GET['login'])){
  15. $username= htmlspecialchars(addslashes($_POST[username]));
  16. $password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST[password]))))))));
  17. $uinfo = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
  18. $checkuser = mysql_num_rows($uinfo);
  19. if($checkuser == '0')
  20. {
  21. echo "Brukernavn ikke funnet";
  22. }
  23. else
  24. {
  25. $udata = mysql_fetch_array($uinfo);
  26. if($udata[userlevel] == 1) {
  27. echo "This account had not been verified.";
  28. }
  29. else
  30. if($udata[password] == $password) {
  31. $query = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error());
  32. $user = mysql_fetch_array($query);
  33. //sets the logged session
  34. $_SESSION['id'] = "$user[id]";
  35. $_SESSION['password'] = "$user[password]";
  36. $online = mysql_query("INSERT INTO `members` (`username`, `online`) VALUES('$username','1')");
  37.  
  38. echo "You are now logged in, Please wait. . .";
  39. echo "<meta http-equiv='Refresh' content='2; URL=index.php'/>";
  40. }
  41. else
  42. {
  43. echo "Incorrect username or password!";
  44. }
  45. }
  46. }
  47. else
  48. {
  49. //If not the above show the login form
  50. echo "<form action='login.php?login' method='post'>
  51. <p>Brukernavn:<input type='text' name='username' />
  52. Passord:<input type='password' name='password' />
  53. <input type='submit' name='login' value='Login' /></p>
  54. Ikke registrert? <a href='register.php'>Klikk her</a>
  55. </form>";
  56. }
  57. ?>
Posted on Sunday 8th July 2007 at 07:58 AM
SkillMaster
SkillMaster's Avatar
Code
$online = mysql_query("INSERT INTO `members` (`username`, `online`) VALUES('$username','1')");


to

Code
$online = mysql_query("UPDATE `members` SET `online` = '1' WHERE `username` = '$username'");

Enjoy
Login or register to respond to this forum topic.