存储$ _GET并在POST请求中再次使用它

亚什·卡兰克

我正在尝试存储$_GET在变量中,并在POST请求中重复使用它们,但是问题是,一旦发送POST请求,URL就会变空,没有任何内容可以存储在变量中,或者存储在变量中的数据将被删除因为网址中没有任何内容

[email protected]&token=M3XK5HeCZy 当前网址

发送POST请求后,URLsuccess.php不再存储任何内容,

我正在尝试根据此方法更新用户密码

我已经尝试了$_SESSION,但无法弄清楚,我目前的工作

if(!$_GET['email'] && !$_GET['token']) {
    header("Location: register.php");
}
else {


$arrayCookie = array('email' => $_GET['email'] , 'token' => $_GET['token']);
$json = json_encode($arrayCookie);
setcookie('data',$json,time()+(8400));

$cookie = $_COOKIE['data'];
$cookie = stripslashes($cookie);
$cookieSavedArray = json_decode($cookie,true);

print_r($cookieSavedArray);

include 'UserActions.php';
$msg="";
$checkEmail = new UserActions();
$checkEmail->databaseConnection('localhost', 'root', '', 'placement2018');
}

HTML表格

<form action="success.php" enctype="multipart/form-data" method="post">
                    <div class="col-sm-12">
                            <div class="form-group">
                                <label>Password</label>
                                <input type="password" name="pass" placeholder="Enter password" class="form-control" required>
                            </div>
                        <div class="form-group">
                            <label>Confirm Password</label>
                            <input type="password" name="confirmpass" placeholder="Confirm password" class="form-control" required>
                        </div>
                            <input class="btn btn-lg btn-info" type="submit" name="addPassword" value="Submit">
                        </center>

现在,一旦提交表单,URL参数就不存在了,因此我想存储URL参数,因为我需要基于该参数运行查询。

如何存储$ _GET参数,使其也保留在$ _POST请求中?

亚什·卡兰克

这就是我解决此问题的方式,我相信这有点像破解,但它确实有效,我仍在寻找更好的解决方案。

验证
如果URL中没有参数,它将被重定向

 if(!$_REQUEST['email'] && !$_REQUEST['token']) {
     header("Location: register.php");
 }

如果找到参数,则:

if(isset($_POST['addPassword'])) {
  $email = htmlentities($_POST['email']);
  $token = $_POST['token'];
  $password=$_POST['pass'] ;
  $confirm = $_POST['confirmpass'] ;
  if($password == $confirm) {
      if($checkEmail->checkTokenEmail($email,$token)) {
          $password = password_hash($password,PASSWORD_BCRYPT);
          if($checkEmail->setAccountActiveAndInsertPassword($email,$password)) {
              $msg = "<p style='color:green;text-align:center;'>Successfuly set password, you may login now</p>";
        }
      } else {
        $msg = "<p style='color:red;text-align:center;'>This link is expired</p>";
    }
  }  
}

最后,在之前$_POST我保存请求$email,并$token在一个隐藏字段,这样我可以在进一步查询中使用它

<form action="success.php" enctype="multipart/form-data" method="post">
<div class="col-sm-12">
    <div class="form-group">
        <label>Password</label>
        <input type="password" name="pass" placeholder="Enter password" class="form-control" required>
    </div>
    <div class="form-group">
        <label>Confirm Password</label>
        <input type="password" name="confirmpass" placeholder="Confirm password" class="form-control" required>
    </div>
    <input type="hidden" value="<?php echo $_REQUEST['email'];?>" name="email">
    <input type="hidden" value="<?php echo $_REQUEST['token'];?>" name="token">
    <center>
        <input class="btn btn-lg btn-info" type="submit" name="addPassword" value="Submit">
    </center>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何存储和还原画布以再次使用它?

如何将来自登录页面响应的 cookie 存储在变量中,并在进一步的请求中使用它

存储值并在同一个控制器 Spring MVC 中再次使用

如何从Redux存储中获取数据并在React Native的组件中使用它

如何从异步存储中检索数据并在组件中使用它?

如何将命令存储在变量中并在管道中使用它?

从存储过程中获取返回值并在程序中使用它

如何存储值并在同一xml文件中重复使用它?

是否可以在存储过程中创建本地临时表并在存储过程返回后继续使用它?

拍摄一些手动存储在Firebase存储中的图像,并在我的React Native应用中使用它

存储变量并在整个域中使用它

将代码存储在列中并使用它

如何在数据库中存储图像URL并在ASP.NET MVC中使用它?

如何将字体系列存储到数组中并在 react.js 的选择选项中使用它

从 SQL 中的存储过程返回值 true 或 false 并在带有 dapper 的 asp core3 中使用它

如何在 local.properties 中存储地图 API 密钥并在 AndroidManifest.xml 中使用它

如何对存储在表中的值执行按位运算,并在sql查询的where子句中使用它?

如何在 Jmeter 中存储提取的 RegEx 并在下一个采样器中使用它

将HTTP POST请求存储在书签或与GET请求类似的内容中

我如何存储给定的响应(作为TextView给出)并再次使用它们来给出响应

将 $.each() 值存储在变量中并使用它

如何在变量中存储非自封闭标签并在render()方法中调用它?

将方法存储在数组中并在C#中调用它们

如何将数据存储在单个文件中并在视图文件中调用它?

在 YAML 中存储多个网络设备并在 jinja2 中引用它

使用Storable存储哈希并在另一个脚本中使用它

SCSS循环-存储变量并在另一个循环中再次使用

在提供的数组中存储后删除所有 httprequest,如 get、post、file 请求

在MySQL中存储Matlab数组。再次