Jump to content

users account update

- - - - -

  • Please log in to reply
8 replies to this topic

#1
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
Good day everyone. Mr Alexandra from this site has developed this code for me and I want to use it now for another purpose. I need to close users account if the user did not login or access the account for two days. Please how do i proceed. I modified Mr Alexander Codes as follows

<?php

    if( !isset($_SESSION) ) { session_start(); }

    $database_db="cat";

    $user_db="root";

    $password_db="root";

    $host_db="localhost";

    

    // connect to database

   $link=mysql_connect($host_db,$user_db,$password_db) or die ("couldnot connect: ".mysql_error());

    mysql_select_db($database_db, $link)  or exit('Error Selecting database: '.mysql_error());

      

    // escape user input for database protection

    $userid = mysql_real_escape_string($_POST["userid"]);

    $password = mysql_real_escape_string($_POST["password"]);

    

    // get user count from database, as that is all we need

    $user = "SELECT count FROM usertab WHERE userid='$userid' AND password='$password'";

    $userres = mysql_query($user);


    // fetch the single user row we had selected

    $row = mysql_fetch_row($userres);

    

    // check if the user exists first

    if(mysql_num_rows($userres) != 0) {

        // check if the user did not login or access the account for 2 days

        if($row[0]  2*24) {

            echo "Error - Your account has been closed.";

        } else {

            //successful login, increment count by one

            mysql_query("UPDATE usertab SET count = count + 1 WHERE userid = '$userid'");

            //redirect them to the page

            echo "Should be redirected now";

        }

    } else {

        //if their username and password returned nothing

        echo "Error - Your account does not seem to exist.";

    }

?>

I set 2*24 hours

#2
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
okay I now added this > 2*24*60. my question is will it work.
24 = hours
60 = minutes
2 = days

Thanks

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Try running this on a separate page first, and only run it once (with the stuff you need to connect to the database above it)
mysql_query("ALTER TABLE usertab ADD lastlogin timestamp NOT NULL DEFAULT NOW()");
You would only run this once to alter the table.

Once that is done, timestamps should be updated each time the user logs in, and if they do not, we close their account (in this case simply delete it) and warn them of this, the following is lightly tested:
<?php
    if( !isset($_SESSION) ) { session_start(); }
    $database_db="cat";
    $user_db="root";
    $password_db="cyberworld";
    $host_db="localhost";
    
    // connect to database
    mysql_connect($host_db,$user_db,$password_db) or die ("couldnot connect: ".mysql_error());
    mysql_select_db($database_db, $link)  or exit('Error Selecting database: '.mysql_error()); ;
    
    // escape user input for database protection
    $userid = mysql_real_escape_string($_POST["userid"]);
    $password = mysql_real_escape_string($_POST["password"]);
    
    // get user count from database, as that is all we need
    $user = "SELECT count, lastlogin FROM usertab WHERE userid='$userid' AND password='$password'";
    $userres = mysql_query($user);

    // fetch the single user row we had selected
    $row = mysql_fetch_row($userres);
    
    // check if the user exists first
    if(mysql_num_rows($userres) != 0) {
        // check if the user has logged in 3 times already
        if($row[0] > 2) {
            echo "Error - You have logged in three times.";
        // check if user has not logged in within two days in seconds
        } elseif ((time() - strtotime($row[1])) > (2 * 24 * 60 * 60)) {
            echo "Error - You have not logged in within two days";
            // close the account (delete it for example)
            mysql_query("DELETE FROM usertab WHERE userid = '$userid'");
        } else {
            //update their last login
            mysql_query("UPDATE usertab SET lastlogin = NOW() WHERE userid = '$userid'");
            
            //successful login, increment count by one
            mysql_query("UPDATE usertab SET count = count + 1 WHERE userid = '$userid'");
            //redirect them to the page
            header("Location: insert1.php");
        }
    } else {
        //if their username and password returned nothing
        echo "Error - Your account does not seem to exist.";
    }
?> 

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
Thanks Mr. Alexander everything is working fine. Your code is excellent. I really appreciate your style. Please Mr Alexander is it possible to enable the users account after 2 days account expiration.let say a link eg enable.php where one can enter only the username to enable the account back until if the user do not make use of the account, it will lock again.
thanks

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
All you would need to do is make enable.php update their last login again so it is within the last two days, for example:
mysql_query("UPDATE usertab SET lastlogin = NOW() WHERE userid = '$userid'");

Then they will be able to log in, try coding it and I will help if something goes wrong!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#6
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
Thanks very much I have implemented it and now waiting for at least 24 hours to see the result because i set it to 1 * 24 * 60 * 60 ,. thanks a lot. Please Mr. Alexander , Are good in java I mean jsp/servlets
thanks

#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
I do not know servlets or Java, although you can feel free to post in our Java help section and see if somebody does.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#8
mutago

mutago

    Programmer

  • Members
  • PipPipPipPip
  • 102 posts
Thanks and remain bless

#9
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
I am glad I could help you on this!
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users