1. Go to this page and download the library: Download sanchescom/php-wifi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Sanchescom\WiFi\Value\Credentials;
use Sanchescom\WiFi\WiFi;
$wifi = WiFi::create();
$network = $wifi->scan()->bySsid('My-WiFi-Network');
$wifi->connect($network, Credentials::password('secret123'));
use Sanchescom\WiFi\Exception\NetworkNotFound;
use Sanchescom\WiFi\Exception\NoAddress;
use Sanchescom\WiFi\Exception\WrongPassphrase;
try {
$wifi->connect('Home', Credentials::password($typed));
} catch (WrongPassphrase) {
// the network is there and refused the passphrase
} catch (NetworkNotFound) {
// no such network in range
} catch (NoAddress) {
// joined, but no DHCP lease
}
use Sanchescom\WiFi\WiFi;
$wifi = WiFi::create();
foreach ($wifi->knownNetworks() as $known) {
printf("%s (%s)\n", $known->name, $known->active ? 'active' : 'saved');
}
use Sanchescom\WiFi\Value\HotspotConfig;
use Sanchescom\WiFi\WiFi;
$wifi = WiFi::create();
$hotspot = $wifi->startHotspot(new HotspotConfig(ssid: 'femus-setup', password: 'change-me-now'));
printf("%s on %s\n", $hotspot->ssid, $hotspot->device);
$response = $portal->handle($method, $path, $_POST); // null when the path is not one of the three
if ($response !== null) {
$response->send();
}
use Sanchescom\WiFi\Backend\BackendFactory;
use Sanchescom\WiFi\Shell\ShellCommandRunner;
$backend = BackendFactory::forLinux(ShellCommandRunner::forCurrentOs());
// NmcliBackend when NetworkManager is running, WpaCliBackend otherwise.
$ php bin/wifi device
wlan0
[exit 0]
$ php bin/wifi list
1 network(s) broadcast no SSID (hidden); they are shown as "-".
SSID BSSID Channel Band Quality dBm Frequency Connected Security
-------------------------------------------------------------------------------------------------
BELL340 0e:ac:8a:99:58:5c 1 2.4 87% -56 2412 false WPA2
VTECH_5764_9764 a6:97:5c:b7:97:64 1 2.4 70% -65 2412 false WPA2
BELL340 0e:ac:8a:99:58:5d 157 5 64% -68 5785 false WPA2
- 0e:ac:8a:99:58:5e 157 5 64% -68 5785 false WPA2
[exit 0]
bash
composer
ini
# /etc/polkit-1/localauthority/50-local.d/php-wifi.pkla
[php-wifi]
Identity=unix-user:www-data
Action=org.freedesktop.NetworkManager.network-control;org.freedesktop.NetworkManager.wifi.scan;org.freedesktop.NetworkManager.settings.modify.system
ResultAny=yes
ResultInactive=yes
ResultActive=yes