PHP发送自动sysdate和sysdate + 24小时

时间:2016-07-20 09:20:15

标签: php

我正在通过变量传递到卷曲调用,我需要通过系统日期(YMD HMS格式),当有人注册时,然后到期日24小时后:

$post2 = [
    "subscription[name]" => 'magazine one day subscription',
    "subscription[product_id]" => '51',
    "subscription[start_date]" => "date('Y-m-d H:i:s')",
    "subscription[end_date]" =>  "date('Y-m-d H:i:s', strtotime('+24 hours', time()))",
    "subscription[allowed_no_of_articles]" => '56',

];

$username = "Incisive";
$password = "!atseg9$";



$ch2 = curl_init("http://xxxx.auth.xxx.net/subscriber_individuals/$xml->id/subscriptions.xml");
curl_setopt($ch2, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $post2);

$complete = curl_exec($ch2);

curl_close($ch2);

echo $complete;

我已经尝试了日期功能,这不起作用,所以我想知道是否有其他人有解决方案尝试任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您引用了date功能。您可以替换:

$post2 = [
    "subscription[name]" => 'magazine one day subscription',
    "subscription[product_id]" => '51',
    "subscription[start_date]" => "date('Y-m-d H:i:s')",
    "subscription[end_date]" =>  "date('Y-m-d H:i:s', strtotime('+24 hours', time()))",
    "subscription[allowed_no_of_articles]" => '56',
];

有了这个:

$post2 = [
    "subscription[name]" => 'magazine one day subscription',
    "subscription[product_id]" => '51',
    "subscription[start_date]" => date('Y-m-d H:i:s'),
    "subscription[end_date]" =>  date('Y-m-d H:i:s', strtotime('+24 hours', time())),
    "subscription[allowed_no_of_articles]" => '56',
];