Hello guys I really need your help. I Had created attendance system but I stucked up with time in button.

I have created a time out and time in button and both are working fine and great but the main problem is that I am unsuccessful for making the time in that when user sign's in and click's on time in button will not work anymore until the next day starts.It means for example shift starts at 6:00 the user sign in and clicks on time in so user cannot click again until he comes next day at 6 the time in button would be click able at that time

Can you guys please help me out with this concern??. I would be really really thankful for this kind help.

Here are some codes that I would like to share with you

My home page code for time in and time out :

code :

<script language="javascript">

function timeout()

    document.form1.action = "settime.php?uid=<?php echo $uid?>";

function timein() 
    document.form1.action = "timein.php?uid=<?php echo $uid?>";



and this is the code where the timin and time out function shows :

<form name="form1" method="post" action= "" >
    <div id="time-status">
    <h4>Time Status</h4>
                $query = "select * from presence where uid=".$uid." and date='".$date."'";
                $recordset = mysql_query($query);
                while($record = mysql_fetch_array($recordset)){
                $count = 1;
                $lasttimein = $record["timein"];
                echo "<table><tr><td>Your Time In :</td><td> ",$lasttimein,"</td></tr></table>";
                $lasttimeout = $record["timeout"];
                echo "<table><tr><td>Your Time Out :</td><td> ",$lasttimeout,"</td></tr></table>";
    <input type="button" name="button3" value="Time Out" onClick="timein()" class="button">
    <input type="button" name="button2" value="Time Out" onClick="timeout()" class="button">

and please do let me know if you also be requiring to see the code for timein.php page which I had created for timein function.

Thank you in advance GOD bless you all :)

Kind Regards Usman Khan

Edited by Dani: Formatting fixed; Be sure to indent all code and leave a blank live above/below

3 Years
Discussion Span
Last Post by UK-1991

Just a guess but have a isLoggedIn field in the database. Set that to true when the user logs in, after the end of the day when work finishes set everyone to LoggedOut just in case someone forgets to clock out.


Idea is really good but let me get out with the issue I stated above wating for the responses no one is helping me with this issue relly disapponted :(


Disappointed you may be... but isn't my answer relevant to the question being asked? Or am I missing something?


Thank you for your kind response bro but the one you suggested me I beleive was a suggesstion which I will use later on and if I faced any problem will ask you.

But the question I asked was about time in button to be disabled and can be clickable once a day as now it can be clicked about 100 times a day. So that is the main issue.

But the thing you told me about is amazing I did'nt thought about it that yes any one can forgot to time out as it will be auto so according to your guidance I will create a table and wil name them isLoggedIn and another field and wil name it loggedout and wil set that to true am I correct ?? but hey how it will work I will try taht as well.

But before bro can you help me out with time in button ??

Thank You

Kind Regards
Usman Khan


once a day as now it can be clicked about 100 times a day.

Well if you had a isLoggedIn variable to check against, you could do something like...

if (isLoggedIn($userid) == true)
  //disable button or do a redirect



You can easily calculate this through the unix timestamp.

for example, to get today at 6AM and tomorrow at 6AM, you would do something like this.

$today = strtotime('today 6am');
$tomorrow =  strtotime('tomorrow 6am');


## hours of operation
$open = strtotime('6am');
$close = strtotime('6pm');

based on those sets of information about time, you can easily create what you need to do with the clicked.

another example,



    $now = time();
    $_SESSION['last_login'] = $now;


capturing the last logout

    $now = time();
    $_SESSION['last_logout'] = $now ;

calculating the elapsed time since last login

$now = time();
$elapsed_time_since = ($now - $_SESSION['last_login']);

calculating total time the user is logged in based on session

$total_time_logged_in = ($_SESSION['last_logout'] - $_SESSION['last_login']);

calculating if the user is entitled to click on the crazy button

if($total_time_logged_in >= $tomorrow){
    $button = true;



        $button = false;


  echo ($button ? '<input type="submit" name="login" value="login" />' : 'Sorry No button for you little lazy rascal');

I have given you almost 5 possible options. You should be able to solve this problem.

Edited by veedeoo: more info added


@iamthwee your idea not working when i placed that the button disappeared


Hello @veedeoo,

Sorry to say but your code does'nt work. did you saw my code which i used for time in kindly I request you to let me know how to disable that button once clicked in a day.

Really appreciated


I'm a bit confused with regard to the use of javascript in all this.
Please correct me if I'm wrong. The process you need is...

User logs into site
User clicks clock-on button
Button now disappears while this user is logged on until roughly the same time the next morning.
The clock-off button is displayed the whole time (after clock-on is clicked) until it itself is clicked.
If clicked before say 06:00 (following day), then no buttons will be shown until that specified time or until 00:00 (midnight) is reached.

The user can log in and out as many times as required - but they will only ever see one button (or perhaps none).

The cosmetic front-end is neither here nor there - the logic behind the DB manipulation is the key component.

settime.php?uid=<?php echo $uid?>

That I do not understand. If the user is logged in (username/password), then passing the user's db id around makes no sense. Use a session variable for this. This is a potential security hole, as a savvy user could just go to the url directly and enter...


Of course user #675 is actually not their real id - they're just being malicious.


Hello @diafol, sir I was wating for your response and I got it really happy to see your response on my thread thank you.

Okay according to your words I typed settime.php?uid=675 but it say invalid uid or pw I had made a checksession which I had pasted on the head that is

    $uid = $_SESSION["uid"];            

okay according to the confussion you have let me tell you what I am looking for let say you create a simple button which do some work now you want any user or you by your self when you or any one clicks that button once that button is clicked it will be disabled once clicked and will be reactive after 24 hours that is equal to 1 day.

Like the button will be available to be clicked after 24 hours once clicked I hope I make it clear to you.

Some one told me to create a function that will solve your problem but that code dose'nt work as you know on button only we can put one function not 2 am i right?

here is that code :

    if ($dateLastPressed < $aDayAgo) {
       echo '<input type="submit" class="myButton" id="option" value="submit" disabled = "disabled"/>';
    else {
       echo '<input type="submit" class="myButton" id="option" value="submit"/>';

what you say about this code by seeing my code would this work or if this one is correct than how should I implement it according to my code.

I have also attached an image of my front end page incase you want to see the visual or what the output is the image is attached as well.

Well I hope I had made everything clear to you and the one you asked

The cosmetic front-end is neither here nor there - the logic behind the DB manipulation is the key component.

settime.php?uid=<?php echo $uid?>

it means that when action is performed like when the button is clicked it will get the settime.php file and will stamp the time for that user which uid has clicked I am sorry i am not good in explaining I hope I had made everything clear to you??

the above settime is lighty different from login and time in time in button is manually not like when user logged in autumatically time is saved in db .

Thank You once again for your precious time sir.

Kind Regards
Usman K

Edited by UK-1991: image was not attached

Attachments home.jpg 397.31 KB

OK, the user is logged in - so has a UID stored in a session variable. Great, that makes things easier.

You need to be clear about the "permission to sign-in" period.

Will this run only once from 00:00 to 23:59 ?

If you set it to this, then you don't have to worry about not being allowed to sign-in until 06:00. Perhaps a user signed-in late at 06:37 one day, which if you make it 24 hours before they can log in again, they will never be able to log in before 06:37, even if they want to.

Is there a maximum length that a user can be signed in for? Can they go beyond midnight (00:00) ? Are they restricted to a maximum of 8 hours, for example, since signing on?

A little more info would allow us to steer you in the right direction. The interface (buttons) is trivial to sort out. The logic for "permission" is the more involved stuff.



Great to hear that. Hmm by the way i did'nt thought about this hmm we have 2 shifts running on one starts at 6:00 and the second one at 9:00 its an human to come late office once or twice a week :P.

This will run from 6:00 PM to 6:00 AM

So what will you suggest to give an interval I just want to secure it like not to be clicked again within their working hours we have 9 hours working shift mean 6:00 office starts all the way till 6 in the morning :).

So what will you say what will be your suggetion.

Please let me know if you need more info I will provide more and more as much as I can


User can signin at any time for example between 6:00 pm to 6:00 am but we have to make sure he cannot be able to click on time in button again and again by mistake or accedently


OK so recognized shifts are as follows:

06:00 - 15:00
09:00 - 18:00

So maybe it really doesn't matter about start time. You could reset allowed clock-on at 00:00 (or even 05:50 and possibly 08:50).

You could have a setup like this - or something similar ...

uid {autoinc} | username | pw | ... 
shift_id {autoinc} | startshift {time} | endshift {time} 
shiftuser_id {autoinc} | uid {int} | shift_id {int} | shift_startdate {date}
work_id {autoinc} | uid {int} | workdate {date} | clock_in {time} | clock_off {time}

An admin sets the shift pattern for each employee - with the ability to set different ones at future dates (shift_startdate)

When the employee logs in, the system retrieves the current shift pattern for the employee and decides upon the allowed clock-in and clock-out times.

e.g. -10 mins for clock-in and +10 mins for clock-off - or whatever you wish it to be. With the ability to work just a single hour (1 hour):

So for 06:00 - 15:00 this could be
allowed clock-in = 05:50 - 14:00
allowed clock-off = 07:00 - 15:10

I've done this so that employees who cannot work a full day, for whatever reason, e.g. hospital appt etc, can work at least one hour during that day.
Ideally there should be two clock-in and clock-off periods to allow for this if the employee has an appt where they could work either side of this, but perhaps that is getting more complicated.

This sort of setup offers some flexibility as you could have a "config" table:

parameter | value
prestart  | 10
postend   | 10
laststart | 60
firstend  | 60

prestart could allow 10 minutes before shift starts e.g. (05:50), but not before
postend would allow 10 minutes after shift ends e.g. (15:10), but not after
laststart would allow employee to start at 14:00 but not later
firstend would allow employee to start at 07:00 but not earlier

That's just an example.

So let's assume that user logs in and session stores the uid, startshift and endshift times and also checks for a 'work' record for that user and for that date.

Consider these scenarios:

No clock-on button if...

  • Before startshift - prestart
  • After endshift - laststart
  • Work record already exists for that date

No clock-off button if...

  • After endshift + postend
  • Before startshift + firstend
  • Work record already exists for that date and the clock_off field is not NULL

For all other scenarios, show the buttons.


@diafol Helo Sir how are you I am sorry my system was out of order and couldn't tried your suggettion please allow me some time i will foresure try this and will let you know if suceeded or not but want to let you know one major problem which I forgot to mention you about is time and date.

We are having evening shifts that is only one shift which starts at 6:00 PM to 3:00 AM midnight

for example 6:00 PM (01-02-2014) to 3:00 AM (02-02-2014) it means within 1 day shift the date is changed. So i decided to place a time zone of ('USA/Arizona') would this will work ?? as my system time will be same as it was time zone of (UTC+05:00) Islamabad, Karachi

so I wil try your idea at its best one

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.