PHP cURL POST请求不会发送?

时间:2018-02-01 06:35:12

标签: php mysql curl post

我正在尝试使用cURL和PHP更新mySQL数据库,但是应该由帖子发送的值不会插入到数据库中。我没有得到任何错误,并且根据phpinfo()启用了cURL。这是我的剧本:

<?php

  $data = [
    'email' => 'jsnow@got.com',
    'token' => '58938539'
  ];

$string = http_build_query($data);
$ch = curl_init("http://www.econcentre.com/receiver.php");

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_exec($ch);
curl_close($ch);

?>

这是接收器脚本:

<?php
   require 'includes/db.php';  // Database connection. Connects with no errors raised

   if(isset($_POST['email']) AND isset($_POST['token'])) {
     $email = $_POST['email'];
     $token = $_POST['token'];

     $q = "INSERT INTO reset_tokens(email, token)";
     $q .= " VALUES(?, ?)";
     $stmt = $pdo->prepare($q);
     $test = $stmt->execute([$email, $token]);
 }

?>

1 个答案:

答案 0 :(得分:0)

您似乎缺少 http://www.econcentre.com/receiver.php 的HTTP身份验证。

您应该在cURL请求中包含HTTP Auth:

Is this a good idea?