Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php curl从api使用post数据重定向?_Php_Angularjs_Restful Url_Php Curl - Fatal编程技术网

如何使用php curl从api使用post数据重定向?

如何使用php curl从api使用post数据重定向?,php,angularjs,restful-url,php-curl,Php,Angularjs,Restful Url,Php Curl,实际上,我一直在使用angularjs和RestfullAPI进行忘记身份验证。我将密钥发送到丢失的用户邮件以获取重置密码面板。用户单击邮件()中的验证url以调用以下API private function reset_pwd_confirm(){ if($this->get_request_method() != "GET"){ $this->response('',406); } $verifica

实际上,我一直在使用angularjs和RestfullAPI进行忘记身份验证。我将密钥发送到丢失的用户邮件以获取重置密码面板。用户单击邮件()中的验证url以调用以下API

    private function reset_pwd_confirm(){
        if($this->get_request_method() != "GET"){
            $this->response('',406);
        }
        $verification_id = $this->_request['verification_id']; 
        $user_id = $this->_request['user_id']; 
        if(!empty($verification_id) && !empty($user_id) && $user_id > 0){
            $tm=time()-86400;
            $query = "SELECT user_id FROM user_pwd_reset WHERE user_id='".$user_id."' AND act_key='".$verification_id."' AND time > ".$tm."";
            $get_user = $this->db->get_row($query);                
            if($this->db->num_rows == 1){
                $curl = curl_init('http://localhost:3000/#/reset');
                curl_setopt($ch,CURLOPT_POST, 1);
                curl_setopt($ch,CURLOPT_POSTFIELDS, 'user_id='.$user_id);
                curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");

                curl_exec($curl);               
            }else{
                $success = array('status' => "Failed", "msg" => "key and user are not match.");
                $this->response($this->json($success),404);
            }
        }else{
            $success = array('status' => "Failed", "msg" => "Invaild verification or user id.");
            $this->response($this->json($success),404);
        }

    }        
在这里,我需要移动称为with post user_id的有角度的页面,为此,我使用了curl,如上所述,但它返回错误为“Cannot post/”。 有什么问题吗??请告诉我。 我认为问题是来自http get方法的请求post,是吗?
请给我解决方案…

如果我理解正确,您希望实现的是:

用户单击电子邮件中的链接(即GET请求),它将触发另一个POST请求。对吗? 如果这可以通过服务器端重定向实现,我会感到惊讶。您可以通过javascript在客户端解决这个问题

但是:你真的需要一个POST请求吗? url中已经有一个
验证\u id
。所以,当用户单击它时,服务器可以重置密码或将用户重定向到“密码重置表单”,并使
验证\u id
无效。因此,
验证\u id
最多可使用1次

可以吗

但是如果您真的需要执行POST请求,下面是如何执行的。 一旦用户点击该链接,它将引导他进入类似这样的定制网页

html:


检查此项并发布您的api代码,这样我们就可以看到问题所在。我需要post请求的原因是我需要用该用户id进一步附加密码,并发送post请求以重置密码。这就是为什么我试图用那个url发送post user_id数据。我不想通过post在这里保护user_id,我只是将user_id作为post类型发送,以便在重置api中获取user_id数据,因为由于密码数据,我们只能在重置api中作为post类型数据发送。私有函数reset_pwd(){if($this->get_request_method()!=“post”){$this->response(“”,406);}$data=json_decode(file_get_contents('php://input);如果(!empty($data['user_-id']){$user_-pwd=$data['user_-pwd'];$user_-id=$data['user_-id'];如果(!empty($user_-pwd)){$query=“UPDATE user SET password=”。$data['user\u pwd']。“'WHERE user\u id=”。“$user\u id.”“;}}}/*这是我的重置api
 <body onload="onLoad()">
  <form style="display:none" method="POST" action="some_url" id="myform">
   <input type="hidden" name="user_id" value="your_user_id">     
  </form>
 </body>
 function onLoad() {
   var form = document.getElementById('myform');
   form.submit();
 }