繁体   English   中英

使用PHP使用cURL完成表单(POST)

[英]Complete form with cURL using PHP (POST)

我正在尝试建立一个注册系统,在该系统中,访问我们并注册到我们网站的用户将在辅助网站上拥有一个帐户,以便他们能够看到一些机会。

事情就这样了: 我要在网站上张贴表格并注册

到目前为止我的代码

    <?php
    // set post fields
    $post = [
    // this i don't master fell free to approach the subject for future reffrance
    'authenticity_token'=>'vhmPffEAIiIbjo36K8CI77+YDQfMPBWEG8ymplsGJ0w=',
    'user[email]'=>'test@gmail.com',
    'user[first_name]'=>'test',
    'user[last_name]'=>'test',
    'user[password]'=>'12345678',//smart password (had to be 8char long)
    'user[country]'=>'Country(placeholder)',
    'user[mc]'=>'1560', //id of the country
    'user[lc_input]'=>'1475', //id of the dropdown
    'user[lc]'=>'1475',//id of the dropdown
    'commit'=>'REGISTER',//value of submit

    ];

    $ch = curl_init('https://auth.aiesec.org/users/sign_in');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

    // execute!
    $response = curl_exec($ch);

    // close the connection, release resources used
    curl_close($ch);

    // do anything you want with your response
    var_dump($response);
    ?>

故事:

作为用户,我希望能够在域A上填写表格,并同时使用CURL甚至JS和AJAX在域B上拥有一个帐户。

如果您有解决方案,请告诉我:)您也可以在网站上查看。

谢谢!

后期编辑

邮递员POST帐户

我已经在POSTMAN中做到了。 所以我认为我应该能够将该信息发布。 如果您还有其他建议。

在这种情况下,服务器返回500作为成功,返回200作为错误(安全性)

最终工作守则

    <?php

    // set post fields
    $post = [
    // this i don`t master fell free to approach the subject for future reffrance
    'authenticity_token'=>'NKWAg8mGA9gUueBaJ5Og+oEOC5O2rZarZzMK+GnjuCA=',
    'user[email]'=>'',
    'user[first_name]'=>'',
    'user[last_name]'=>'',
    'user[password]'=>'',//smart password (had to be 8char long)
    'user[country]'=>'',
    'user[mc]'=>'', //id of the country
    'user[lc_input]'=>'', //id of the dropdown
    'user[lc]'=>'',//id of the dropdown
    'commit'=>'REGISTER',//value of submit

    ];

    $ch = curl_init('https://auth.aiesec.org/users/');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);


    // execute!
    $response = curl_exec($ch);

    // close the connection, release resources used
    curl_close($ch);

    // do anything you want with your response
    var_dump($response);


    ?>

您通过https连接。 因此,您应该添加以下行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

我测试了您的代码,网站回复“用户名/密码错误”。 这意味着卷曲连接正确。

暂无
暂无

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

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