Restricting Access to Page php with Port

1

I'm doing a login environment and would like this page to serve only an access port previously configured as "8080". I'm using an Apache server and it will be installed by me on the Linux machine.

Would this interfere with another site if kept on the same Apache server? Unrelated to this login system?

    
asked by anonymous 08.05.2016 / 20:25

1 answer

1

The first thing is to make sure your web server is set up to answer on the port you want to have login .

As you mentioned using Apache, the relevant configuration is here:

  

link

Basically, to answer on different ports, you can set listen :

Listen 80
Listen 8080

Or if the application meets different IPs and different ports:

Listen 192.0.2.1:80
Listen 192.0.2.5:8080

Remembering that if the application of a port is different from the other, you can configure virtualhosts (the listen must be open for all the ports it will use):

<VirtualHost *:80>
    DocumentRoot /www/caminho_para_o_site
</VirtualHost>
<VirtualHost *:8080>
    DocumentRoot /www/caminho_para_o_painel
</VirtualHost>
  

link

If you do not want to complicate, and the panel will be hosted next to the main site, you can use the information in $_SERVER['SERVER_PORT'] to know if the port used is correct:

See a simplified example:

<?php
   if( $_SERVER['SERVER_PORT'] != 8080 ) {
       echo '<h1>Porta n&atilde;o autorizada</h1>';
       // faz o que quiser aqui, no caso da porta estar errada
       // pode simular um 404, ou redirecionar pra onde achar melhor

       die(); // Importantissimo garantir que o script termine aqui
   }

   ... aqui continua sua página ...

Now, if you configure this part of the site to serve only on the 8080, the test itself is unnecessary. You need to analyze within your concrete situation to determine the best way.

    
08.05.2016 / 20:30