Closed Jack-Piotrowski-MAT-Holdings closed 5 years ago
First of all, you should never need to change the contents of the Client.php
file. The protected properties there have a purpose.
Secondly I believe you’re using an incorrect value for site_id, the fourth parameter for the constructor. Please read this section of the README: https://github.com/Art-of-WiFi/UniFi-API-client#important-notes
Okay, I just undid all changes I made to the Client.php file.
So now the constructor looks like this:
I read the Important Notes section, went to my Controller's UI and found this in the url:
https://
So 'default' is my $site_id
So I changed the $site value (4th variable in Client.php's constructor) to 'default'
When I saved everything and refreshed the page that my login script is running it still returned 'false.'
Is there anything else that might be the culprit?
Thank you for your help,
Jack
Can you enable debug mode (pass true without quotes) and see what the output is?
That debug response is actually for this code: (very slightly different than the code I posted before--taken from auth_guest_basic.php)
require_once("vendor\autoload.php");
require_once('config.php');
$mac = '
Hmmm, I’m not seeing the string “default” in the URLs. Are you 100% sure you are passing the value in the correct way?
Well the 'default' string should be inserted into the URL inside of the login() function, right?
And I include the config and create a new instance of the Client class, so it should be getting the $site_id value from Client.php, which has it set to 'default'.
Also make sure you pass a valid MAC address to this function.
I added a valid MAC address to the function. Still same results.
Thats not how PHP OOP programming works. The constructor creates a new instance of the Class which has several specific properties such as the site id.
Oh, wait! I hard-coded 'default' as the site_id: $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, 'default', $controllerversion);
And it returned true.
So what do I have to change to make it so $site_id in the below line of code actually refers to the $site value inside of Client.php?: $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion);
Something like this?
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $unifi_connection->site, $controllerversion);
I'm sorry, nevermind. I figured it out.
Thank you so very much for taking the time to help me.
I hope you have a wonderful morning/afternoon/night wherever you are!
Best regards,
Jack
No problem, you're welcome. You too, here it's almost midnight (CET timezone).
By the way, feel free to share the resolution here for other readers.
Hi,
I have cloned the UniFi-API-client repository, loaded its libraries with composer and filled out the config appropriately with the correct username, password, https://*.*.*.*:8443, and my controller version.
I then created a new file 'login.php':
require_once("vendor\autoload.php"); require_once('config.php'); $unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $site_id, $controllerversion); $set_debug_mode = $unifi_connection->set_debug($debug); $loginresults = $unifi_connection->login();
I do not get any errors on loading: require_once("vendor\autoload.php"); require_once('config.php');
Contents of config.php:
$controlleruser = 'admin'; // the user name for access to the UniFi Controller $controllerpassword = '*****'; // the password for access to the UniFi Controller $controllerurl = 'https://*.*.*.*:8443'; // full url to the UniFi Controller, eg. 'https://22.22.11.11:8443' $controllerversion = '5.10.23'; // the version of the Controller software, eg. '4.6.6' (must be at least 4.0.0) $debug = false;
The login function simply returns "false", so it is not getting the $_SESSION['unificookie'] value.
I checked all of the settings on my controller's UI, and I did not find anything I needed to enable to allow calls like this.
Do you know of anything in the Controller UI that might fix this problem?
Maybe my client.php's config values?
client.php config values:
Should the $baseurl be something other than my local host?
I appreciate any and all help!
Thank you,
Jack