简体   繁体   English

将数据从php脚本转发到日历

[英]Forward data from php script to calendar

I have a project where I need to do the following: retrieve some data from a form, fill the database, create a response for the user and post the data to a third party. 我有一个项目,需要执行以下操作:从表单中检索一些数据,填充数据库,为用户创建响应并将数据发布到第三方。 To give an example, it's like booking a ticket to a concert.The ajax call: You buy the ticket, you receive a response (whether the purchase was successful), a php script sends data to the database, and someone may be announced that a new ticket was bought. 举个例子,就像预订音乐会门票一样.ajax调用:购买门票,您会收到响应(无论购买是否成功),一个php脚本会将数据发送到数据库,并且可能会宣布有人买了一张新票。 Now, I need to pass data to that "someone". 现在,我需要将数据传递给该“某人”。 Which is what I don't know how to do. 我不知道该怎么办。

Or, like when someone posts a comment to my question on stackoverflow, I get a notification. 或者,就像有人在我对stackoverflow的问题发表评论时,我收到通知。

In my particular case, the user creates an event, receives a response and I will need to have certain parameters posted by the user on a calendar. 在我的特定情况下,用户创建一个事件,接收响应,并且我将需要用户在日历上发布某些参数。 It is important that I could hardly integrate the calendar with the script retrieving the data. 重要的是,我几乎无法将日历与检索数据的脚本集成在一起。 I would rather need to "forward" the data to the calendar- quite like pushing notifications. 我宁愿将数据“转发”到日历中,就像推送通知一样。
Can anyone please give me a clue what should I use, or what should I need in order to do the above? 任何人都可以给我一个提示,我应该使用什么,或者我需要什么才能完成以上操作?

The process will go like this: 该过程将如下所示:

    AJAX   
user----> php script->database
                 |_ calendar   

So if i get you right, you could post your data to the calendar via curl: 因此,如果我找对了,您可以通过curl将数据发布到日历中:

$url = "http://www.your-url-to-the-calendar.com";
$postData = array(
    "prop1" => "value1",
    "prop2" => "value2",
    "prop3" => "value3"
);
//urlify the data for the post
$data_string = "";
foreach ($postData as $key => $value)
    $data_string .= urlencode($key) . '=' . urlencode($value) . '&';
$data_string = rtrim($data_string, '&');
//will output --> prop1=value1&prop2=value2=prop3=value3

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_HEADER => false,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => false,
    CURLOPT_POST => count($postData),
    CURLOPT_POSTFIELDS => $data_string
));
$result = curl_exec($ch);

If your third party calendar does not require authentication than this would be the best way to post it, if you can not write to the database yourself. 如果您的第三方日历不需要身份验证,那么如果您自己无法写入数据库,则这是发布日历的最佳方法。 When it requires authentication you would have to first login via curl (send credentials via curl-post, receive cookies, send cookies with your data) 当需要身份验证时,您必须首先通过curl登录(通过curl-post发送凭据,接收cookie,发送包含数据的cookie)

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM