Use classes remotely in php

1

Good morning!

I'm trying to create a "serial" verification system with php. It would work more or less like this. On an X server it will store the views of server Y; On server Y I would just have a html template where these views would be displayed.

But for this X Server needs to compare a key, like a verification serial, as in some desktop programs that when you buy it receives a registry key. This key would be stored on server Y and would be fixed, Server X will store in its own database, txt or wherever possible. several of these keys.

I apologize if I was not clear, but I have been since 6 am yesterday trying and so far I have not achieved anything viable. One detail, the server Y can not know how to store this information, it only needs to confirm if the keys hit and receive the views of the X server.

          <!DOCTYPE html>
    <html lang="pt-br">
    <head>
        <meta charset="UTF-8">
        <title>Teste</title>
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <link rel="stylesheet" type="text/css" href="css/form.css">
        <script src="js/main.js"></script>
    </head>
    <body>
        <img id="logo-top" src="img/logo.png" alt="">
        <div id="wrapper">
            <?php
            include_once 'http://servidor.com.br/end/ctl/Version.class.php';
            ?>
        </div>
        <footer>
        </footer>
    </body>

    </html>
        <?php
class Version {
    private $client;
    private $server = array("!01@1-1#20-15$0-3%14",
                            "!01@1-1#20-15$0-3%15");

    public function checarVersao($link){
        $ponteiro = fopen($link, "r");

        while(!feof($ponteiro)) {
            $linha = fgets($ponteiro, 4096);
            $this->client = $linha;

            if(in_array($linha, $this->server)) {
                switch($linha) {
                    case "!01@1-1#20-15$0-3%14":
                        include_once '../viw/index.php';
                        break;
                    case "!01@1-1#20-15$0-3%15":
                        include_once '../viw/erro404.php';
                        break;
                }
            } else {
                echo '<script>alert("Erro no serial");</script>';
                echo '<div id="serial-incorreto">serial incorreto! verifique o serial fornecido e tente novamente.</div>';
            }
        }
        fclose($ponteiro);
    }
}
$version = new Version();
$version->checarVersao('servidor.com.br/end/serial.txt');

?>
    
asked by anonymous 01.12.2015 / 11:58

1 answer

1

Well, maybe what you want to do is something like this:

Server A

$chave = 'XXXYZ';

SERVER B

$chave = 'XXXYZ';

SERVER B will be the server that will return the requested external file information. However, all this request will have to go through the main script, so as not to have problems of direct access by others.

SERVER B

#request.php

$arquivo = $_GET['nome_arquivo'];

$chaveCliente = $_GET['chave'];

if ($chave === $chaveCliente) {
     include DIRETORIO_PADRAO . $arquivo . '.php';
} 

SERVER A:

 $opts = array(
      'http'=>array(
         'method'=> 'GET',
         'content' => http_build_query([
                   'chave' => $chave,
                    'nome_arquivo' => 'view_cadastro'
                  ])

       )
 );


 $dados_view = file_get_contents('http://www.servidor-b.com/request.php', false, $opts);

I do not recommend this operation in any way, but the one you asked for, I tried to do it in the safest way possible.

    
01.12.2015 / 12:20