note 80259 added to ref.radius
| From: | SysCo/al-developer | Date: | Mon, 07 Jan 2008 01:39:10 +0000 |
| Subject: | note 80259 added to ref.radius | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134903@lists.php.net to get a copy of this message | ||
Pure PHP radius class (do not need the radius package !)
We have implemented a pure PHP radius class following the RFC 2865 rules. Using this class, it is
also possible to do WWW realm authentication.
Class abstract, full class implementation (LGPL) with helper files and examples can be found at http://developer.sysco.ch/php/
<?php
// (...)
class Radius
{
// (...)
public function Radius($ip_radius_server = '127.0.0.1', $shared_secret = '',
$radius_suffix = '', $udp_timeout = 5, $authentication_port = 1812, $accounting_port =
1813)
{
// (...)
}
// (...)
function AccessRequest($username = '', $password = '', $udp_timeout = 0)
{
// (...)
$_socket_to_server = socket_create(AF_INET, SOCK_DGRAM, 17); // UDP packet = 17
if ($_socket_to_server === FALSE)
{
// (...)
}
elseif (FALSE === socket_connect($_socket_to_server, $this->_ip_radius_server,
$this->_authentication_port))
{
// (...)
}
elseif (FALSE === socket_write($_socket_to_server, $packet_data, $packet_length))
{
// (...)
}
else
{
// (...)
$read_socket_array = array($_socket_to_server);
$write_socket_array = NULL;
$except_socket_array = NULL;
$received_packet = chr(0);
if (!(FALSE === socket_select($read_socket_array, $write_socket_array,
$except_socket_array, $this->_udp_timeout)))
{
if (in_array($_socket_to_server, $read_socket_array))
{
if (FALSE === ($received_packet = @socket_read($_socket_to_server, 1024))) // @
used, than no error is displayed if the connection is closed by the remote host
{
// (...)
}
else
{
socket_close($_socket_to_server);
}
}
}
else
{
socket_close($_socket_to_server);
}
}
// (...)
return (2 == ($this->_radius_packet_received));
}
}
?>
Example
<?php
require_once('radius.class.php');
$radius = new Radius('127.0.0.1', 'secret');
if ($radius->AccessRequest('user', 'pass'))
{
echo "Authentication accepted.";
}
else
{
echo "Authentication rejected.";
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 212.74.141.30
----
Manual Page -- http://www.php.net/manual/en/ref.radius.php
Edit -- https://master.php.net/note/edit/80259
Del: integrated -- https://master.php.net/note/delete/80259/integrated
Del: useless -- https://master.php.net/note/delete/80259/useless
Del: bad code -- https://master.php.net/note/delete/80259/bad+code
Del: spam -- https://master.php.net/note/delete/80259/spam
Del: non-english -- https://master.php.net/note/delete/80259/non-english
Del: in docs -- https://master.php.net/note/delete/80259/in+docs
Del: other reasons-- https://master.php.net/note/delete/80259
Reject -- https://master.php.net/note/reject/80259
Search -- https://master.php.net/manage/user-notes.php