单击取消时如何删除令牌

时间:2013-05-23 23:23:13

标签: php

如果用户点击取消,我如何获得用户请求的令牌注意如果单击取消,则从db中删除特定令牌并且用户被重定向到index.php,用户不必输入任何内容真的不知道在哪里以及如何开始所以请耐心等待,不管怎样,下面是token.php

<?php
error_reporting(0);
session_start();
$token=$_GET['token'];
include("settings.php");
connect();
if(isset ($_POST['submit'])){
$q="select email from tokens where token='".$token."' and used=0";
$r=mysql_query($q);
while($row=mysql_fetch_array($r))
   {
$email=$row['email'];
   }
If ($email!=''){
          $_SESSION['email']=$email;
}
else die("Invalid link or Password already changed  <a href='../index.php'>Click here to go back to the HOME PAGE<a/>");}
$pass=$_POST['password'];
$email=$_SESSION['email'];
if(isset($_POST['password'])&&isset($_SESSION['email']))
{
$q="update registration set password='".md5($pass)."' where email='".$email."'";
$r=mysql_query($q);
if($r)mysql_query("update tokens set used=1 where token='".$token."'");echo "Your password is changed successfully  <a href='../index.php'>Click here to go back to the HOME PAGE<a/>";
if(!$r)echo "An error occurred";
    }

以下是formreset.php

<h3><strong>Forgot Password</strong></h3>
      <form name="forgot" method="POST" id="forgot" action="includes/reset.php?token=<?php echo $_GET['token']; ?>">
        <div align="center">
          <table width="372" border="0">
            <tr>
              <td width="181"><p>&nbsp;</p>
              <p><strong>Password</strong></p></td>
              <td width="181"><span id="sprytextfield1"><span id="sprypassword1">
              <label for="password2"></label>
              <br />
            <input type="password" name="password" id="password2" />
                <br />
                <span class="passwordRequiredMsg">Your PASSWORD is need</span></span>
<label for="label"></label>
              </span></td>
</tr>
            <tr>
              <td height="22"><p>&nbsp;
              <p><strong>Confirm Password</strong></p></td>
              <td><span id="spryconfirm2">
              <label for="password"></label>
              <span id="spryconfirm1">
              <label for="password1"></label>
              <br />
              <input type="password" name="password1" id="password1" />
              <br />
              <span class="confirmRequiredMsg">Please re-confirm your PASSWORD</span><span class="confirmInvalidMsg">The PASSWORDS don't match.</span></span></span></td>
</tr>
</table>
</div>
    <div align="center">
      <p>&nbsp;</p>
      <table width="372" border="0">
        <tr>
          <th width="132" scope="row"><input type="submit" name="submit" id="submit" value="submit" /></th>
          <th width="113" scope="row"><a href="includes/cancel.php?token=<?php echo $_GET['token']; ?>">Cancel</a></td></th>
          <th width="113" scope="row"><input type="reset" name="clear" id="clear" value="Clear" /></th>
        </tr>
      </table>
    </div>
    <div align="center">
      <table width="372" border="0">
        <tr> </tr>
        <tr> </tr>
      </table>
    </div>thanks in advance
  </form>

所以我该怎么做呢

1 个答案:

答案 0 :(得分:0)

这样的东西?

$token = mysql_real_escape_string($_GET['token']);
mysql_query("DELETE FROM tokens WHERE token='$token'") or die (mysql_error());
header("Location: index.php");