How to implement a 511 response from the server?

if($enable==0)
{
# here sends unauthorized users firewall
 if ($_SERVER['SERVER_NAME'] != "$servername.$domain_name")
{

 header("location:http://$servername.$domain_name/index.php?add=" .
 urldecode($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
exit;
 }


Know that the authorization header has the following form
header('HTTP/1.1 511 Network Authentication Required', TRUE, 511);

please tell me how
the right implement to unauthorized users is immediately sent to captive portal detection?
March 12th 20 at 08:39
1 answer
March 12th 20 at 08:41
Solution
511 Network Authentication Required — the answer is sent not by the server, which was intended query, and a mediation server such as server provider — in the case that the client must first log in to the network, for example, to enter a password for paid access point to the Internet. It is assumed that the response body will be returned to the Web login form or redirect to it. Introduced in the draft standard RFC 6585

You write for a paid access point to the Internet. ?
try by analogy with the 301
<?php 
 header("HTTP/1.1 511 Network Authentication Required "); 
 header("Location: http://www.host.ru"); 
 exit(); 
 ?>
You probably did not understand me, I mean the kind of realization that when you select the menu wireless networking my free network, as usually configured on Mikrotik, you immediately throw in the browser to enter authorization data. And redirect I have configured Iptables rules. - Shyann.Reilly commented on March 12th 20 at 08:44
trying to do analog https://global-hotspot.ru ?
then something not so implemented already. - darrel_Kilba commented on March 12th 20 at 08:47
I'm trying to implement a hotspot with iptables rules and Php, the system is already fully working, gives the address and registration by SMS, the only thing that is not convenient for registration it is necessary to open the browser,but I noticed in some places when getting ip address from the server, opens the browser and comes to a page with the registrations. here it is this I need to when getting the ip off the page. I heard something about DHCP authentication, but nothing yet therefore it is not found. - Shyann.Reilly commented on March 12th 20 at 08:50
if ($_SERVER['SERVER_NAME'] != "$servername.$domain_name")
{
 header('HTTP/1.1 511 Network Authentication Required', TRUE, 511); 
 header("location:http://$servername.$domain_name/index.php?add=" .
 urldecode($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
exit;
}

if(!empty($_GET['add'])){
 if(!empty($_POST['code'])){ // sign that submachine form, filling the fields for code from SMS
 // mark it autorizovanem
 // don't know what You need to do to $enable was Troyes
}
 // draw authorization form which will be sent postом .

}
- darrel_Kilba commented on March 12th 20 at 08:53
@darrel_Kilba,
#check if this mac in the database
$dbmac = mysqli_query($link,"SELECT mac FROM DataUsers WHERE ip='$ip'");
$dben = mysqli_query($link, "SELECT enable FROM DataUsers WHERE ip='$ip'");
$rows_db = mysqli_num_rows($dbmac);
$enable = 0;
for ($i=0; $i < $rows_db; $i++)
{
 $dbmac_i = mysqli_result($dbmac,$i);
 if($dbmac_i == $mac) {$enable = mysqli_result($dben,$i);}

}
if($enable==0)
{
 header('HTTP/1.1 511 Network Authentication Required', TRUE, 511);
 if ($_SERVER['SERVER_NAME'] != "$servername.$domain_name")
{

 header("location:http://$servername.$domain_name/index.php?add=" .
 urldecode($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));

exit;
}
 if (!isset($_POST['access_code']))
{
 if ((!isset($_POST['tel'])) || ($_POST['tel'] < 9000000000))
{
 print_header(); ?>
- Shyann.Reilly commented on March 12th 20 at 08:56
header('HTTP/1.1 511 Network Authentication Required', TRUE, 511);
look on the branches if I where to invest and not to constantly send.
the logic of this.
- if not authorized
--- if this submit
------ if the code is correct
--- otherwise
------ if this url output forms , there is a get parameter add
------------ draw it
------ otherwise
------------ forwards 511 code - darrel_Kilba commented on March 12th 20 at 08:59
@darrel_Kilba Well I like doing, if there is a Mac in the database, check the status ebanle(1 has access,0 no) , if no Mac in the Database, then access is 0, send him to register, even if there is a Mac in database but dustup 0, since daily updating iptables, send us back the registration. in the same branch. - Shyann.Reilly commented on March 12th 20 at 09:02
Again. You constantly send the pen direction unless authorized.
Oversimplify the task.
make two files
index.php and login.php

in the index
remains
if($enable==0)
{
 header('HTTP/1.1 511 Network Authentication Required', TRUE, 511);
 header("location:http://$servername.$domain_name/login.php?add=" .
 urldecode($_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']));
exit;
}


in login
<?php
if (isset($_POST['access_code']))
{
 // what needs to be checked and entered into the database
 // to send a man where he wanted to go
exit;
}
}
?>
html form code
- darrel_Kilba commented on March 12th 20 at 09:05
@darrel_Kilba did follow Your advice, but to no avail :( Apparently not destiny. - Shyann.Reilly commented on March 12th 20 at 09:08
as everything is built ?
Here I am a new customer and open mesh.
I had the ip . Next ? - darrel_Kilba commented on March 12th 20 at 09:11
that the DNS queries happening while I'm not authorized ? But if my phone is configured to use my DHCP is issued ?

$servername.$domain_name - external server know ? - darrel_Kilba commented on March 12th 20 at 09:14
it did not help . finally read the user manual
tools.ietf.org/html/rfc6585
https://ru.wikipedia.org/wiki/Captive_portal - darrel_Kilba commented on March 12th 20 at 09:17

Find more questions by tags DebianApachePHP