如何在我的用户页面上添加倒数计时器

时间:2017-03-06 06:44:04

标签: javascript php html

请帮忙!我有一个用户页面设置并正确链接到我的数据库。我想要做的是为没有激活帐户的用户添加3小时的倒数计时器。我希望该计时器对于个人用户是唯一的,一旦他们注册他们的帐户就开始计数,当他们登录倒计时时,将显示在页面上。请问,任何人都可以帮我一个简单的代码来实现这个吗?非常感谢。

PS:我是代码编写的假人,因此我使用Dreamweaver来帮助我生成代码。

这是我的网页代码:

<?php require_once('Connections/TurboFund.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "Received1")) {
  $updateSQL = sprintf("UPDATE users SET AcceptedFrom1=%s WHERE UserID=%s",
                       GetSQLValueString($_POST['Received2'], "text"),
                       GetSQLValueString($_POST['UserIDHiddenField1'], "int"));

  mysql_select_db($database_TurboFund, $TurboFund);
  $Result1 = mysql_query($updateSQL, $TurboFund) or die(mysql_error());

  $updateGoTo = "dashboardactivated.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "Received1")) {
  $updateSQL = sprintf("UPDATE users SET AcceptedFrom1=%s WHERE UserID=%s",
                       GetSQLValueString($_POST['Purge'], "text"),
                       GetSQLValueString($_POST['UserIDHiddenField2'], "int"));

  mysql_select_db($database_TurboFund, $TurboFund);
  $Result1 = mysql_query($updateSQL, $TurboFund) or die(mysql_error());

  $updateGoTo = "dashboardactivated.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_User = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_User = $_SESSION['MM_Username'];
}
mysql_select_db($database_TurboFund, $TurboFund);
$query_User = sprintf("SELECT * FROM users WHERE Username = %s", GetSQLValueString($colname_User, "text"));
$User = mysql_query($query_User, $TurboFund) or die(mysql_error());
$row_User = mysql_fetch_assoc($User);
$totalRows_User = mysql_num_rows($User);
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60745 -->
    <meta charset="utf-8">
    <title>Contacts</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="style.responsive.css" media="all">

<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <script src="jquery.js"></script>
    <script src="script.js"></script>
    <script src="script.responsive.js"></script>
<meta name="description" content="Description">
<meta name="keywords" content="Keywords">


<style>.art-content .art-postcontent-0 .layout-item-0 { color: #232324; background: ;  }
.art-content .art-postcontent-0 .layout-item-1 {  border-collapse: separate;  }
.art-content .art-postcontent-0 .layout-item-2 { border-style:Solid;border-width:2px;border-color:#7C7C7E; color: #CBCBCD; background: #08BFBC; padding: 0px;  }
.art-content .art-postcontent-0 .layout-item-3 { border-style:Solid;border-width:3px;border-color:#444446; padding: 0px;  }
.art-content .art-postcontent-0 .layout-item-4 { border-bottom-style:Solid;border-left-style:Solid;border-bottom-width:2px;border-left-width:2px;border-bottom-color:#B4B4B6;border-left-color:#B4B4B6; color: #565658; background: #ECECEA;  }
.art-content .art-postcontent-0 .layout-item-5 { border-top-style:Solid;border-right-style:Solid;border-bottom-style:Solid;border-top-width:2px;border-right-width:2px;border-bottom-width:2px;border-top-color:#B4B4B6;border-right-color:#B4B4B6;border-bottom-color:#B4B4B6; color: #565658; background: #ECECEA;  }
.art-content .art-postcontent-0 .layout-item-6 { color: #777779; background: ;  }
.art-content .art-postcontent-0 .layout-item-7 { margin-top: 0px;margin-bottom: 0px;  }
.art-content .art-postcontent-0 .layout-item-8 { border-style:Groove;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-color:#B4B4B6;border-right-color:#B4B4B6;border-bottom-color:#B4B4B6;border-left-color:#B4B4B6;  border-collapse: separate;  }
.art-content .art-postcontent-0 .layout-item-9 { border-style:Solid;border-width:2px;border-color:#7C7C7E; color: #FFFFFF; background: #08BFBC; padding: 0px;  }
.art-content .art-postcontent-0 .layout-item-10 { border-style:Groove;border-width:2px;border-color:#444446; color: #777779; background: ; padding: 0px;  }
.art-content .art-postcontent-0 .layout-item-11 { border-right-style:Solid;border-bottom-style:Solid;border-left-style:Solid;border-right-width:2px;border-bottom-width:2px;border-left-width:2px;border-right-color:#B4B4B6;border-bottom-color:#B4B4B6;border-left-color:#B4B4B6; color: #565658; background: #E5E5E6;  }
.art-content .art-postcontent-0 .layout-item-12 { border-style:Solid;border-width:2px;border-color:#7C7C7E; color: #FFFFFF; background: #08BFBC;  }
.art-content .art-postcontent-0 .layout-item-13 { border-style:Solid;border-width:3px;border-color:#444446; color: #777779; background: ;  }
.art-content .art-postcontent-0 .layout-item-14 { border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-right-width:2px;border-bottom-width:2px;border-left-width:2px;border-right-color:#B4B4B6;border-bottom-color:#B4B4B6;border-left-color:#B4B4B6; color: #565658; background: #E5E5E6;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

</style>
</head>
<body>
<div id="art-main">
<header class="art-header">

    <div class="art-shapes">
        <div class="art-object1332516260"></div>
<div class="art-object7306249"></div>
<div class="art-object1873331263"></div>

            </div>

<h1 class="art-headline">
    <a href="/">Let's Build your financial life together</a>
</h1>
<h2 class="art-slogan">Leadership is influence.</h2>





<nav class="art-nav">
    <ul class="art-hmenu"><li><a href="home.php" class="">Home</a></li><li><a href="log-in.php" class="">Log In</a></li><li><a href="sign-up.php" class="">Sign Up</a></li><li><a href="services.php" class="">Services</a></li><li><a href="how-it-works.php" class="">How It Works</a></li><li><a href="contact-us.php" class="">Contact Us</a></li></ul> 
    </nav>


</header>
<div class="art-sheet clearfix">
            <div class="art-layout-wrapper">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                        <div class="art-layout-cell art-content"><article class="art-post art-article">


                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 100%" >
        <p><br></p>
        <p><span style="color: rgb(66, 66, 67); font-size: 22px; font-family: Georgia;"><span style="color: rgb(106, 106, 108);">Welcome!,</span></span> <?php echo $row_User['Username']; ?>.</p>
    </div>
    </div>
</div>
<div class="art-content-layout layout-item-1">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-2" style="width: 50%" >
        <p style="text-align: center;"><span style="color: rgb(255, 255, 255); font-size: 16px;">Dashboard</span></p>
    </div><div class="art-layout-cell layout-item-3" style="width: 50%" >
        <p style="text-align: center; padding-left: 80px;"><span style="color: rgb(66, 66, 67); font-size: 16px;">Account Information &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span style="color: rgb(66, 66, 67); font-size: 20px;">&nbsp;<a href="" class="art-button">Log Out</a>&nbsp;</span><br></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-4" style="width: 50%" >
        <p style="text-align: center;"><img width="283" height="283" alt="" class="art-lightbox" src="images/generic_avatar_300-2.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; "></p>
    </div><div class="art-layout-cell layout-item-5" style="width: 50%" >
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;">Name:</span> <?php echo $row_User['Fname']; ?></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;"><br></span></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;">Email:</span> <?php echo $row_User['Email']; ?></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;"><br></span></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;">Phone Number:</span> <?php echo $row_User['PhoneNumber']; ?></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;"><br></span></p>
        <p><span style="color: rgb(5, 111, 143); font-family: Tahoma; font-size: 14px;">Bank Account Details:</span> <?php echo $row_User['BankAccDetails']; ?></p>
        <p><span style="color: rgb(5, 111, 143); font-size: 18px;"><br></span></p><p>&nbsp;<a href="" class="art-button">Edit Account Info</a>&nbsp;</p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-6" style="width: 100%" >
        <p><br></p><p><br></p>
    </div>
    </div>
</div>
<div class="art-content-layout-wrapper layout-item-7">
<div class="art-content-layout layout-item-8">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-9" style="width: 50%" >
        <p style="text-align: center;"><span style="font-size: 16px; text-align: center;">Donation</span><br></p>
    </div><div class="art-layout-cell layout-item-10" style="width: 50%" >
        <p style="text-align: left;"><span style="font-size: 14px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #75D43A;">ACCOUNT HAS BEEN CONFIRMED</span></span></p>
    </div>
    </div>
</div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-11" style="width: 100%" >
        <p style="text-align: center;"><br></p><p style="text-align: left;"></p><p style="padding-left: 20px;"><span style="font-size: 14px;">PACKAGE:&nbsp;</span><?php echo $row_User['Donation']; ?>: <?php echo $row_User['StatusDonation']; ?></p>
        <p></p><p style="text-align: center;"><br></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-6" style="width: 100%" >
        <p><span style="color: rgb(48, 48, 49);"><br></span></p><p><br></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-12" style="width: 50%" >
        <p style="text-align: center;"><span style="font-size: 16px;">Earnings</span><br></p>
    </div><div class="art-layout-cell layout-item-13" style="width: 50%" >
        <p style="text-align: center;"><span style="color: #25D402;">ACCOUNT IS ACTIVE</span></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-14" style="width: 100%" >
        <p style="padding-left: 20px; text-align: center;"><br></p><p style="padding-left: 20px; text-align: left;"></p><ul>
          <li><span style="font-size: 14px;">Receive Donation From:</span> <?php echo $row_User['ReceiveFrom']; ?>: <?php echo $row_User['AcceptedFrom1']; ?></li>
        </ul>
        <form action="" method="post" name="Status1" id="Status1" onsubmit="return confirm('Are you sure you want to submit?');">
          <input name="Confirm" type="checkbox" id="Confirm" value="Confirmed" checked="CHECKED" style="display:none;">
          <label for="Confirm"></label>
          <input name="UpdateButton" type="submit" class="art-button" id="UpdateButton" onclick="this.disabled = true" value="Confirm"/>
          <input name="Purge" type="checkbox" id="Purge" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
             <label for="Purge"></label>
             <input name="UpdateButton2" type="submit" class="art-button" id="UpdateButton2" onclick="this.disabled = true" value="Purge"/>
        </form>
        <p><span style="color: rgb(56, 56, 57);"><br></span><span style="color: rgb(56, 56, 57);"><br>
        </span></p>
        <p></p><ul>
          <li><span style="font-size: 14px;">Receive Donation From</span>: <?php echo $row_User['ReceiveFrom2']; ?> : <?php echo $row_User['AcceptedFrom2']; ?></li>
        </ul>
        <form action="" method="post" name="Status1" id="Status2" onsubmit="return confirm('Are you sure you want to submit?');">
          <input name="Confirm2" type="checkbox" id="Confirm2" value="Confirmed" checked="CHECKED" style="display:none;">
          <label for="Confirm2"></label>
          <input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton3" onclick="this.disabled = true" value="Confirm"/>
          <input name="Purge2" type="checkbox" id="Purge2" value="You Will Be Rematched Soon!" checked="CHECKED" style="display:none;">
          <label for="Purge2"></label>
          <input name="UpdateButton3" type="submit" class="art-button" id="UpdateButton4" onclick="this.disabled = true" value="Purge"/>
        </form>
        <p><span style="color: rgb(56, 56, 57);"><br></span></p><p></p><p></p><p><br></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-6" style="width: 100%" >
        <p><br></p>
    </div>
    </div>
</div>
</div>



</article></div>
                    </div>
                </div>
            </div>
    </div>
<footer class="art-footer">
  <div class="art-footer-inner">
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 50%">
        <div style="position:relative;display:inline-block;padding-left:50px;padding-right:50px"><p><span style="font-style: italic; font-weight: bold; font-size: 14px; color: rgb(255, 255, 255); text-shadow: rgb(23, 23, 23) 1px 0px 0px, rgb(23, 23, 23) -1px 0px 0px, rgb(23, 23, 23) 0px -1px 0px, rgb(23, 23, 23) 0px 1px 0px, rgba(0, 0, 0, 0.984375) 0px 0px 10px;">We Advice You Only Use Your Spare Cash!</span></p>

        <p><br>
        </p><br></div>
    </div><div class="art-layout-cell layout-item-0" style="width: 50%">
        <p><span style="font-weight: bold;">Contact Us: <span style="font-size: 15px;">turbofund2017@gmail.com</span></span></p>
    </div>
    </div>
</div>
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 100%">
        <p>Copyright © 2011 TurboFund. All Rights Reserved.<br></p>
    </div>
    </div>
</div>

    <p class="art-page-footer">
        <span id="art-footnote-links">Designed by <a href="www.turbofund.org" target="_blank">TurboFund</a>.</span>
    </p>
  </div>
</footer>

</div>
</body></html>
<?php
mysql_free_result($User);
?>

1 个答案:

答案 0 :(得分:0)

注册新用户时,您可以在用户表的字段中存储时间戳。你也可以使用mysql insert 触发器自动为你做这件事。

当用户登录时,您可以从当前时间戳中减去已注册的时间戳并显示在用户信息中心中。

您也可以使用JavaScript继续在用户仪表板中显示倒计时器,并使用interval或setTimeout。

已编辑:

在您的表格中设置时间戳,您可以简单地将值设置为您的字段,如下所示:

ALTER TABLE `schema`.`users` 
CHANGE COLUMN `created` `created` DATETIME NOT NULL 
DEFAULT CURRENT_TIMESTAMP ON Insert CURRENT_TIMESTAMP ; 
  

注意:在mysql和php中获取时间戳有点不同。

当您尝试登录或当您的工作被解雇时,如果用户未完成注册步骤的时间超过3小时,您可以检查时间并删除用户。类似下面的 php 代码:

if($row["approved"]!=true)//check if user didn't finish registration steps
{
$timest = $row["created"];//you must getting $row info from user table   

$registerTime = strtotime($timest);

$curentTime = time();

if(($curentTime-$registerTime) > 10800) {     //(60*60*3) seconds
  //Delelet your user
}
}