Use classes remotely in php

Asked

Viewed 52 times

1

Good morning!

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

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

I apologize if I wasn’t clear, but I’ve been trying since 6:00 yesterday morning and so far I haven’t achieved anything viable. One detail, the Y server cannot know how this information is stored, it just needs to confirm that the keys match and receive the views from 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');

?>
  • This is looking more like javascript than PHP, huh! Be careful with this operation

  • The problem is the visibility of the code between the two servers. I could not define exactly what this fits, one because php does not compile the files and is server-side, I’ve been reading about web services but I didn’t understand it very well, and it seems useless for this case.

  • 1

    Apparently what you want is to prevent copying or misuse of your code. If it is really that, I already say that it is useless to try these things in PHP. Any programmer with just a little bit of experience breaks this barrier without difficulty.

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 returns the information of the requested external file. But all this request will have to go through the main script, 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 TO:

 $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 in any way this operation, but within what you asked, I tried to do in the safest way possible.

  • I edited the question to post what I could do, it really worked, but it got me into trouble. The main thing is that both servers need to be allow_url_include enabled, and in one of them I don’t have access to php.ini Not to mention that I need it to include itself, and I don’t need to pass parameters through get

  • 1

    My friend, in this case, you can do as I did, but using curl.

  • 1

    From what I saw at first Curl can really solve the problem, grateful for your answers!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.