I try to define variable and then call it in my function, and then i call the function in another file. So, the variables outside the function work properly, but when i call them in function they don't work. Here's the code.
$info = new ServerInfo($server->GetServerData('IPAdress'));
$id = $server->GetServerData('ID');
$sshhost = $server->GetServerData('SSHHOST');
$sshport = $server->GetServerData('SSHPORT');
$sshuser = $server->GetServerData('SSHUSER');
$sshpw = base64_decode(base64_decode($server->GetServerData('SSHPW')));
$port = $server->GetServerData('PORT');
/* Start Server Function */
function start_server($sshhost, $sshport, $sshuser, $sshpw){
global $sshhost;
global $sshport;
global $sshuser;
global $sshpw;
global $id;
global $port;
if (!function_exists("ssh2_connect")) return "SSH2 PHP extenzija nije instalirana";
if(!($con = ssh2_connect($sshhost, $sshport))){
return "Ne mogu se spojiti na server";
} else {
if(!ssh2_auth_password($con, $sshuser, $sshpw)) {
return "Netačni podatci za prijavu";
} else {
$stream = ssh2_shell($con, 'vt102', null, 80, 24, SSH2_TERM_UNIT_CHARS);
fwrite( $stream, "cd /home/cs && screen -A -m -S srv".$id. " ./hlds_run -console -game cstrike +port " .$port. " +map de_dust2 +maxplayers 32 -pingboost 1".PHP_EOL);
sleep(1);
echo "Server Startovan";
return TRUE;
}
}
}