0
I’m so sorry, but I had to rewrite my entire question because I wasn’t being objective enough to make myself understood, when I omit code as was the previous case is not to hide something is just to be able to understand what I respond to within my programming limitations, in any case as soon as the platform is ready I will make it available online.
In this first file the variables will be available so that they can be changed to make connections between the 3 servers the demonstration is for server 1.
#/pasta/config.php
<?PHP
//Atenção ao configurar este ficheiro pois é igual para os 3 servidores
//e terá que ter em mente em que servidor o esta a configurar
//porque tem que descomentar o $serverip correspondente e entre as aspas colocar o seu ip interno de sua rede
//e em $dbL colocar entre as aspas o numero correspondente ao servidor que escolheu 1, 2 ou 3.
$dbL = "1";// Que servidor é este? 1, 2 ou 3.
$serverip1 = "10.0.0.101"; // Ip interno Mysql se for o servidor 1
$db_porta1 = "3306"; // Porta Mysql servidor 1
$db_user1 = "dns"; // Utilizador Mysql servidor 1
$db_password1 = "123456"; // Senha Mysql servidor 1
$db_name1 = "dns"; // Nome base dados Mysql servidor 1
//$serverip2 = "10.0.0.102"; // Ip interno Mysql se for o servidor 2
$db_porta2 = "3306"; // Porta Mysql servidor 2
$db_user2 = "dns"; // Utilizador Mysql servidor 2
$db_password2 = "123456"; // Senha Mysql servidor 2
$db_name2 = "dns"; // Nome base dados Mysql servidor 2
//$serverip3 = "10.0.0.103"; // Ip interno Mysql se for o servidor 3
$db_porta3 = "3306"; // Porta Mysql servidor 3
$db_user3 = "dns"; // Utilizador Mysql servidor 3
$db_password3 = "123456"; // Senha Mysql servidor 3
$db_name3 = "dns"; // Nome base dados Mysql servidor 3
?>
The following 3 files are updated every 60 seconds and the ips have already been checked before entering the servers.
#/pasta/connect/ipserver1.php
<?PHP $s_ipserver11 = "xx.246.142.235";?>
#/pasta/connect/ipserver2.php
<?PHP $s_ipserver22 = "xx.246.142.245";?>
#/pasta/connect/ipserver3.php
<?PHP $s_ipserver33 = "xx.246.142.255";?>
To not do 4 includes on all the missing files I created the following.
#/pasta/connect/ipservers.php
<?PHP
include_once("/pasta/config.php");
include_once("/pasta/connect/ipserver1.php");
include_once("/pasta/connect/ipserver2.php");
include_once("/pasta/connect/ipserver3.php");
?>
This will be the file of this question where I want to input 2 variables or not and output by a third for each connection.
#/pasta/connect/convencao.php
<?PHP
include_once("/pasta/connect/ipservers.php");
//Se existir variável $serverip1 ler valor se não ler valor de $s_ipserver11 mas se existirem as duas ler sempre $serverip1 e responder em $ip1.
//Se existir variável $serverip2 ler valor se não ler valor de $s_ipserver22 mas se existirem as duas ler sempre $serverip2 e responder em $ip2.
//Se existir variável $serverip3 ler valor se não ler valor de $s_ipserver33 mas se existirem as duas ler sempre $serverip3 e responder em $ip3.
if( isset( $serverip1 ) and isset( $s_ipserver11 ) )
{
$ip1 = $serverip1;
}
else
{
if( isset( $serverip1 ) )
$ip1 = $serverip1;
if( isset( $s_ipserver11 ) )
$ip1 = $s_ipserver11;
}
if( isset( $serverip2 ) and isset( $s_ipserver22 ) )
{
$ip2 = $serverip2;
}
else
{
if( isset( $serverip2 ) )
$ip2 = $serverip2;
if( isset( $s_ipserver22 ) )
$ip2 = $s_ipserver22;
}
if( isset( $serverip3 ) and isset( $s_ipserver33 ) )
{
$ip3 = $serverip3;
}
else
{
if( isset( $serverip3 ) )
$ip3 = $serverip3;
if( isset( $s_ipserver33 ) )
$ip3 = $s_ipserver33;
}
$s_ipserver1 = $ip1;
$s_ipserver2 = $ip2; //Coloquei estas 3 variáveis para dar a entender o que preciso mas podem ser apagadas.
$s_ipserver3 = $ip3;
?>
Below are the various forms of connection to understand what I need.
Connection to server 1
#/pasta/connect/connectserver1.php
<?PHP
include_once("/pasta/connect/convencao.php");
$db_host1 = "$s_ipserver1:$db_porta1";
$db_link1 = mysql_connect($db_host1, $db_user1, $db_password1) or die (mysql_error ());
$db_connect1 = mysql_select_db($db_name1, $db_link1);
?>
Connection to server 2
#/pasta/connect/connectserver2.php
<?PHP
include_once("/pasta/connect/convencao.php");
$db_host2 = "$s_ipserver2:$db_porta2";
$db_link2 = mysql_connect($db_host2, $db_user2, $db_password2) or die (mysql_error ());
$db_connect2 = mysql_select_db($db_name2, $db_link2);
?>
Connection to server 3
#/pasta/connect/connectserver3.php
<?PHP
include_once("/pasta/connect/convencao.php");
$db_host3 = "$s_ipserver3:$db_porta3";
$db_link3 = mysql_connect($db_host3, $db_user3, $db_password3) or die (mysql_error ());
$db_connect3 = mysql_select_db($db_name3, $db_link3);
?>
Variables for connection to the local server
#/pasta/connect/connectserverLsub.php
<?php
include_once("/pasta/connect/convencao.php");
$ipserver = 's_ipserver'. $dbL;
$porta = 'db_porta'. $dbL;
$user = 'db_user'. $dbL;
$password = 'db_password'. $dbL;
$name = 'db_name'. $dbL;
?>
Connection to the local server
#/pasta/connect/connectserverL.php
<?PHP
include_once("/rjpdns/connect/connectserverLsub.php");
$host = $$ipserver . ':'. $$porta;
$link = mysql_connect($host, $$user, $$password) or die (mysql_error ());
$db_connect = mysql_select_db($$name, $link);
?>
I hope this time I have exposed and improved my doubt.
There is no
break
to if. It is not very clear what you want.– Papa Charlie
@Rjp, instead of writing comments, it’s better [Edit] the question to add details.
– brasofilo
Yes it’s true you’re right @brasofilo
– Ricardo Jorge Pardal
Yeah, because if someone else comes, you just have to read the question to understand the problem. There’s an explanation of you that’s down there in the answer, and it seems important...
– brasofilo
@Rjp Server, I would like very much if you could solve your problem, but it is not clear what you want. You say you want to validate the ips because they may be wrong, and in Manuel Gerardo Pereira’s comment Voce says: "I know that the ips are valid that there is no doubt". Be clearer with the problem so we can help.
– Papa Charlie
Reorganized and much more complete question.
– Ricardo Jorge Pardal