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ã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.