Control Web Panel
Developers => Functions => Topic started by: porosenoq on November 23, 2016, 07:21:58 PM
-
Hello,
my first post here :)
I am trying to build a module for user registration with payment etc.
I am facing the following problem:
What would be the best approach with the account api ? I am currently trying to use cURL. First the user fills in a form with its desired username, password etc. The form is then submited with POST method to a php file where I am initiating curl session where we pass the form variables to the url, but I always get empty response from server or I get an error that the username is already in the database even if it actually isn't.
my code:
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$domain = $_POST["domain"];
$email = $_POST["email"];
$key = "abv123";
$api = "account_new";
$url = 'http://ip:2030/api/?key='.$key.'&api='.$api.'&domain='.$domain.'&username='.$username.'&password='.$password.'&package=1&email='.$email.'&inode=10000&nofile=100&nproc=25';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$tmp = curl_exec($ch);
curl_close($ch);
if ($tmp === false){
return $tmp;
}
else { echo "success!"; }
?>
Would you be so kind and help me with the best way to achieve what I want ?
-
have you tried to do this manually by using curl from command line ?
-
Hello,
i've got this problem too... So i tried to diagnose, how to solve the problem. I found out that if you run PHP script as user "nobody" (default apache user), it ends up with this error.
I figured it out by saving PHP piece of code to a file, and then running it with cron /usr/local/bin/php /path/to/your/script.php
What surprised me was, that even running a wget in a cron didn't helped.
Hope someone will find this useful, i've spent a whole weekend on this thing :D
-
you need to check the error you get and/or in the logs
-
I checked.
What was kinda weird was that it sent two requests.
In CWP Apache log i found that first response was ok, then CWP resets the connection, and then send the "Username already in database" error because the request is called again.
I think (it's only a thought), that something went wrong in API, and before setting password for the user it ended. Weird is, that it's working in a browser.
What is working correctly is creating a user, everything even with this error, but the user has no password set.
When i was looking in messages log, it says that it could not find a passwd file, i tried to look in CWP code, but it is encrypted/encoded, and i respect the rules, so i did'nt dig deeper, then i was looking for a workaround.
Hope it helps :-)