Jump to content

Guy, how knows Php, Time (Could be a chick too!)


callesson

Recommended Posts

Sure thing, I just wanted help to be confirmed first :D Maybe nobody wanna help me :( haha. But okey lets explain.

First Thing:

I have a submit button that will rederict you to another page. If that submit is set then your not gonna be able to use it again after like 10 or 30 min. So I would like to check that, and without problems with like if its another day or something. Also I would like to calculate the time thats left so I could display it.

__

Sec Thing:

I want something to update every hour. Like for each hour update something +10. I would like it to check like this.

If you logout, and then you login after 2 h you will get 20 of something. And also if you are loged in it will update.  But if there is another way, feel glad to tell :)

__

Ty!

Link to comment
Share on other sites

Sry for that. No dont want you to do it for me xD

 

Well im stuck at the

 

Calculating, and Checking so its the right day.

 

Right now Im adding a time into the Database (Date() + 10 or 30 min) when the submit is set,  then next time its set it will check if date() is > then Database time.

 

And for the second thing, I just want an idea. Cause I have no idea how to do it.

Link to comment
Share on other sites

You could just use cookies to disable the submit button. When the form is loaded, check if the cookie has some kind of value, and if it does, disable it. If it doesn't then dont. When the form got submitted, set a cookie that lasts 30 minutes, or 60 * 30 seconds.

Link to comment
Share on other sites

Siric:

I do not have my code right here, but its as simply as this ( Do not correct this code)

<form ... method="post">
...
<input type="submit" name="submit"/>
...

...
if(isset($_POST['submit']))
{
$time = date() + 10 min;

$up = mysql_query("UPDATE table SET time=$time where user=$_SESSION...");
}
then next time:
$select = mysql_query("SELECT * FROM table where user=$_SESSION...");
$time = $row[time];
$date = date();
if(isset($_POST['submit']) && $date < $time)
{
echo "You cant do this now... Time left x";
}

theocas:

Well, I could check on that. But i havent worked with cookies before.

Link to comment
Share on other sites

You should be using a timestamp,date("U"). Lots easier to check for a few minutes diff and you dont have to worry about what day it is. Then just use an if statement to display the submit button if it within your params.

 

 

HTH

Teamatomic

Link to comment
Share on other sites

This is already answered, but since I am Guy.. thought I had to add my two cents...haha

<?php

$server_local_time = time();           //gives UNIX time (the number of seconds since January 1 1970 00:00:00 GMT)

echo(date("D F d Y",$server_local_time));  // will display something like: Wed April 14 2010   
?> 

 

 

reference code for date() so if you want to use hours obviously... instead of calendar date. Here is the list

Required. Specifies how to return the result:

 

    * d - The day of the month (from 01 to 31)

    * D - A textual representation of a day (three letters)

    * j - The day of the month without leading zeros (1 to 31)

    * l (lowercase 'L') - A full textual representation of a day

    * N - The ISO-8601 numeric representation of a day (1 for Monday through 7 for Sunday)

    * S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)

    * w - A numeric representation of the day (0 for Sunday through 6 for Saturday)

    * z - The day of the year (from 0 through 365)

    * W - The ISO-8601 week number of year (weeks starting on Monday)

    * F - A full textual representation of a month (January through December)

    * m - A numeric representation of a month (from 01 to 12)

    * M - A short textual representation of a month (three letters)

    * n - A numeric representation of a month, without leading zeros (1 to 12)

    * t - The number of days in the given month

    * L - Whether it's a leap year (1 if it is a leap year, 0 otherwise)

    * o - The ISO-8601 year number

    * Y - A four digit representation of a year

    * y - A two digit representation of a year

    * a - Lowercase am or pm

    * A - Uppercase AM or PM

    * B - Swatch Internet time (000 to 999)

    * g - 12-hour format of an hour (1 to 12)

    * G - 24-hour format of an hour (0 to 23)

    * h - 12-hour format of an hour (01 to 12)

    * H - 24-hour format of an hour (00 to 23)

    * i - Minutes with leading zeros (00 to 59)

    * s - Seconds, with leading zeros (00 to 59)

    * e - The timezone identifier (Examples: UTC, Atlantic/Azores)

    * I (capital i) - Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)

    * O - Difference to Greenwich time (GMT) in hours (Example: +0100)

    * T - Timezone setting of the PHP machine (Examples: EST, MDT)

    * Z - Timezone offset in seconds. The offset west of UTC is negative, and the offset east of UTC is positive (-43200 to 43200)

    * c - The ISO-8601 date (e.g. 2004-02-12T15:19:21+00:00)

    * r - The RFC 2822 formatted date (e.g. Thu, 21 Dec 2000 16:01:07 +0200)

    * U - The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

 

Link to comment
Share on other sites

I believe for your first thing you could do this... (Might have some flaws but you should get the picture)

<?php
if(isset($_POST['submit'])) {
   $time = time() + 10000; //10 seconds, so change this to whatever..
   $up = mysql_query("UPDATE table SET time=$time where user='".$_SESSION['blah']."'");
}

echo '<form action="" method="post" >';

$query = mysql_query("SELECT * FROM table where user='".$_SESSION['blah']."'");

if(($row['time'] + 10000) < time()) { //Again.. 10 seconds so change it
   echo '<input type="submit" name="submit" value="submit" disabled />';
   echo 'You cant do this now. Please wait... ' . date('i', $row['time'] - time()) . 'minutes';
} else {
   echo '<input type="submit" name="submit" value="submit" onclick="this.disabled = true" />';
}

echo '</form>';
?>

 

For your sec thing .. if you have a last active collum in the database. which gets updated upon loading on the page by time(), then what you'd do.. if something like..

if(($row['last_active'] + 60000) < time()) {
    //20 something
} 

60000, is 60 seconds.. so that'll need to be changed corresponding to what you wish to do. A simple method is used for the login too. You'll need to get the details from the database based on the user trying to login.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.