gpt4 book ai didi

php - 使用 php curl http post 在 ownCloud 上创建用户

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:43:57 25 4
gpt4 key购买 nike

在 owncloud 相关网站和 stackoverflow 本身的以下链接中,所有相关信息都以损坏的形式出现:

  1. User Provisioning Api - 自己的云
  2. PHP + curl, HTTP POST sample code
  3. Create user on ownCloud using Ajax Jquery
  4. User Provisioning - php Authentication error

我正在尝试做一些非常简单的事情:

  1. 我在我的本地主机上设置了一个 owncloud 服务器,
  2. 我有一个 html 页面,它接收用户名和密码的字符串值
  3. 我发送要由以下 php 脚本处理的页面请求。

    <?phpecho "Begun processing credentials , first it will be stored in local variables" . "<br/>";// Loading into local variables$userName = $_POST['username'];$RRpassword = $_POST['password'];echo "Hello " . $userName . "<br/>";echo "Your password is " . $RRpassword . "<br/>";// Add data, to owncloud post array and then Send the http request for creating a new user$ownCloudPOSTArray = array('username' => $userName, 'password' => $RRpassword );$url = 'http://localhost/owncloud/ocs/v1.php/cloud/users';$ch = curl_init($url);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$response = curl_exec($ch);curl_close($ch);echo "<br/>Created a new user in owncloud";?>

I get the output like:

Begun processing credentials , first it will be stored in local variables
Hello Frank
Your password is frankspassword
failure 997 Unauthorised
Created a new user in owncloud

I also tried to login to own cloud using following php script:

// Login As Admin
$ownAdminname = 'ownAdmin';
$ownAdminpassword = 'ownAdminPassword';

$ch = curl_init('http://localhost/owncloud');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$ownAdminname:$ownAdminpassword");
$output = curl_exec($ch);
curl_close($ch);
echo $output;

即使这个也失败了。

所以简而言之,它不起作用。我也无法通过与 owncloud 类似的脚本登录。这样做的正确方法是什么?我缺少什么设置?有人可以帮忙吗?

最佳答案

由于这个问题专门针对 owncloud,我创建了一个帐户并在 owncloud forum 中发布了一个将此问题链接到它的问题| .

这里是owncloud大师@RealRancor给我推荐的,如下,

Just had another look, maybe its just easy to replace:

$url = 'http://localhost/owncloud/ocs/v1.php/cloud/users';

with

$url = 'http://adminuser:adminpass@localhost/owncloud/ocs/v1.php/cloud/users';

as shown in the documentation.

令人惊讶的是,它就像一个魅力。所以这里是整个修改后的 php 脚本:

<pre>
&lt;?php
echo "Begun processing credentials , first it will be stored in local variables" . "<br/>";

// Loading into local variables
$userName = $_POST['username'];
$RRpassword = $_POST['password'];

echo "Hello " . $userName . "<br/>";
echo "Your password is " . $RRpassword . "<br/>";

// Login Credentials as Admin
$ownAdminname = 'ownAdmin';
$ownAdminpassword = 'ufi2016%%';


// Add data, to owncloud post array and then Send the http request for creating a new user
$url = 'http://' . $ownAdminname . ':' . $ownAdminpassword . '@localhost/owncloud/ocs/v1.php/cloud/users';
echo "Created URL is " . $url . "<br/>";

$ownCloudPOSTArray = array('userid' => $userName, 'password' => $RRpassword );

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Response from curl :" . $response;
echo "<br/>Created a new user in owncloud<br/>";

// Add to a group called 'Users'
$groupUrl = $url . '/' . $userName . '/' . 'groups';
echo "Created groups URL is " . $groupUrl . "<br/>";

$ownCloudPOSTArrayGroup = array('groupid' => 'Users');

$ch = curl_init($groupUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArrayGroup);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo "Response from curl :" . $response;
echo "<br/>Added the new user to default group in owncloud";

?>
</pre>

这是输出:

Begun processing credentials , first it will be stored in local variables
Hello Frank
Your password is frankspassword
Created URL is http://ownAdmin:ufi2016%%@localhost/owncloud/ocs/v1.php/cloud/users
Response from curl : ok 100
Created a new user in owncloud
Created groups URL is http://ownAdmin:ufi2016%%@localhost/owncloud/ocs/v1.php/cloud/users/Frank/groups
Response from curl : ok 100
Added the new user to default group in owncloud

关于php - 使用 php curl http post 在 ownCloud 上创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34566729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com