nukeko
1
this code is good??
$API = new routeros_api();
$API->debug = false;
if ($API->connect('192.168.0.1', 'nukeko', 'wkd4496')) {
$BRIDGEINFO = $API->comm('ip/hotspot/user/print', array(
".proplist" => ".id",
"?address" => "$ip"
));
$API->comm('ip/hotspot/user/set', array(
".id"=>$BRIDGEINFO[0]['.id'],
"profile"=>"suspendido"
));
////
im try to make cut online for my users but this code not work, someone know why isthe problem this?? thanks for help…
Commands must start with “/”. Other than that, the code seems fine.
You should make a check somewhere if $BRIDGEINFO[0][‘.id’] is set. It won’t be if $ip doesn’t exist in the list.
nukeko
3
ok im show you de code complete, is a file with im try make to change profile from users to “default” to “suspendido”..
<?php
require('routeros_api.class.php');
$servidor = "localhost";
$usuario = "root";
$clave = "thundercache";
$basedatos = "clientes";
$fecha_db=date("Y-m-d");
$fecha_db = explode("-",$fecha_db);
$fecha_cambiada = mktime(0,0,0,$fecha_db[1],$fecha_db[2]-3,$fecha_db[0]);
$fecha = date("Y-m-d", $fecha_cambiada);
$conexion=mysql_connect ($servidor, $usuario, $clave) or die ('problema conectando porque :' . mysql_error());
mysql_select_db ($basedatos,$conexion);
$cadena ="SELECT * FROM usuarios where fecha='".$fecha."'";
$tabla = mysql_query($cadena, $conexion) or die ("problema con cadena de conexion<br><b>" . mysql_error()."</b>");
$registros = mysql_num_rows($tabla);
while ($registro = mysql_fetch_array($tabla)){
$id=$registro['id'];
$ip=$registro['ip'];
//// registro de pago
$link = mysql_connect("localhost","root","thundercache");
mysql_select_db("clientes",$link);
/// ACTIVAMOS CLIENTE
$link = "UPDATE usuarios SET estado='VENCIDO' Where id='".$id."'";
$result = mysql_query($link);
$API = new routeros_api();
$API->debug = false;
if ($API->connect('192.168.10.1', 'admin', '050684')) {
$BRIDGEINFO = $API->comm('ip/hotspot/user/print', array(
".proplist" => ".id",
"?address" => "$ip"
));
$API->comm('ip/hotspot/user/set', array(
".id"=>$BRIDGEINFO[0]['.id'],
"profile"=>"suspendido"
));
////
}
$API->disconnect();
mysql_close($link);
//// mikrotik
}
mysql_close($conexion);
?>
the problem is that code do not make change the profile… 
janisk
4
wait for 5.12 but then again, you have to force logout for users in local database.
Replace:
$BRIDGEINFO = $API->comm('ip/hotspot/user/print', array(
".proplist" => ".id",
"?address" => "$ip"
));
$API->comm('ip/hotspot/user/set', array(
".id"=>$BRIDGEINFO[0]['.id'],
"profile"=>"suspendido"
));
with
$BRIDGEINFO = $API->comm('/ip/hotspot/user/print', array(
".proplist" => ".id",
"?address" => "$ip"
));
$API->comm('/ip/hotspot/user/set', array(
".id"=>$BRIDGEINFO[0]['.id'],
"profile"=>"suspendido"
));
and try it again.
(that’s what I had in mind with "Commands must start with “/”. ")
janisk
7
just diff it
notice the starting / for commands that should have been there.
nukeko
8
ahhhhhhhhhhhhhhhhhhhhhh ok ok I got it
…sorry i dont see the “/” now im try
thanks
nukeko
9
the code is work, i made app whit php and msql + API to mikrotik and working so good, thanks for you help 