Hello Guys,
i have installed PEAR2\Net\RouterOS and it is working very well. Is there anyway i can make the script to run automatically at intervals?
The file which contains the code is mikro.php. if open my web browser and type : localhost\hotspot1\mikro.php
users will be uploaded to the userman. Instead of refreshing a web browser each time there is a new user in the sql,is there anyway we make the script to run automatically
The work around i did was to allow the user to click on a link to activate so that the browser refreshes but there could be a better way of doing it.
My code is below:
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';
//$db = mysqli_connect('localhost','root','', 'dbname');
try {
$client = new RouterOS\Client('172.17.65.1', 'admin', 'Uspf2019!');
//$router = new RouterOS\Client('172.16.7.3', 'admin', 'password@1');
$mysqli = new mysqli('localhost:3306', 'user1', 'password@1', 'hotspot');
echo 'successfully registered!Click <a href= "http://fuotuoke.org/login.html">here</a> here to login';
$client->sendSync($addRequest = new RouterOS\Request('/tool user-manager user add' ));
//$router->sendSync($addRequest = new RouterOS\Request('/tool user-manager user add' ));
$users = $mysqli->query("SELECT `Firstname`, `Lastname`, `Email`, `StaffID` AS `username`, `password`,
`Telephone`, `Location` FROM `staff_register`");
while($user = $users->fetch_object()) {
$addRequest
->setArgument('customer', 'admin')
->setArgument('shared-users', '6')
->setArgument('username', $user->username)
->setArgument('password', $user->password)
->setArgument('first-name', $user->Firstname)
->setArgument('last-name', $user->Lastname)
->setArgument('email', $user->Email)
->setArgument('phone', $user->Telephone)
->setArgument('location', $user->Location)
->setArgument('copy-from', 'master-staff');
$client($addRequest);
//$router($addRequest);
}
} catch (RouterOS\SocketException $e) {
echo 'Connection to RouterOS failed... ' . $e;
} catch (RouterOS\DataFlowException $e) {
echo $e->getMessage();//Wrong username or password; probably
} catch (Exception $e) {
echo 'Unknown exception... ' . $e; //Connection fail to MySQL; probably
}
?>