The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: Login once per week

  1. #1

    Login once per week

    I need to achieve limiting a user to login once per week.

    The week starts on Mondays. So if the user logs in on thursday, they cannot login until the following monday. If they login monday then cannot login until the next monday. How can I achieve this?

    I would like to use PHP to figure out the timing and then just store the value into a last logged in field and just test the current time against the last logged in time

  2. #2
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    if you're using php, why not simply stash a timestamp of when they last logged in to your server and then simply do a week check in php...

    The following code should form a useful basis for a script to check whether a timestamp falls within the bounds of a weekly time period...

    PHP Code:
     
     $nowMK 
    mktime000date("n"), date("j"), date("Y") ); // j = days
     
    echo $nowMK "<br/>\n";
     
    $nowInt = ( date("w") == ) ? date("w");
     echo 
    $nowInt "<br/>\n";
     
     
     
    $startMK mktime000date("n"), date("j") - $nowIntdate("Y") );//
     
    echo $startMK "<br/>\n";
     
    $endMK mktime000date("n"), date("j") + (7-$nowInt), date("Y") );//
     
    echo $endMK "<br/>\n";
     
     echo 
    '$nowMK ===> ' date("r"$nowMK) . "<br/>\n";
     echo 
    '$startMK ===> ' date("r"$startMK) . "<br/>\n";
     echo 
    '$endMK ===> ' date("r"$endMK) . "<br/>\n"
    Hope this helps anyway man...

    good luck!
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  3. #3
    Thanks for the reply. I noticed this week starts on sunday. How can I make it so it starts on monday?

  4. #4
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    You shouldn't need to...

    Once you get your datestamp out of MySQL (or wherever it's stored) simply do another mktime on it, or get it into a readable format for the comparison, and then simply say...

    Code:
     
    if ( mydate >= $startMK ){
        if ( mydate < $endMK ){
     
          // Do Something...
     
       }
    }
    Sorry for the pseudo code, but I'm in the middle of something, so trying to keep my thoughts on track...
    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  5. #5
    I'd approach it this way:
    PHP Code:
    <?php
        $last_login_stamp 
    1253309760// <=== Sept. 18, 09 (store in db as last login), of course this would change
        
    $last_login_date date('d F Y'$last_login_stamp); // Convert timestamp to readable format
        
        
    $next_monday_stamp strtotime("$last_login_date next Monday"); // Get the timestamp of the Monday following last login (store in the db as next new login date)
        
    $next_monday_date date('d F, Y',$next_monday_stamp);

        echo ( 
    time() <= $next_monday_stamp ) ? "login fail - you can not login until $next_monday_date"login success - refresh last login and generate new login date"// compare current time w/ the next login date to see if user can log in
    ?>
    You don't have to store the next monday stamp in the db, but it may be helpful
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  6. #6
    Thanks guys. So far I am having most success with simplistik's method

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012