PHP Classes

Pure PHP radius class: Authenticate users with a RADIUS server

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 72%Total: 2,272 All time: 1,716 This week: 41Up
Version License PHP version Categories
radius_class 1.2.5GNU Lesser Genera...5.3.0Networking, User Management
Description 

Author

This class can be used to authenticate users with a RADIUS network access server according to RFC 2865.

It connects to a Radius server given its IP address and requests access on behalf of an user given his password.

Once authenticated the class may return the attributes of the authorized user.

This class works with at least the following RADIUS servers:

- Authenex Strong Authentication System (ASAS) with two-factor authentication
- FreeRADIUS, a free Radius server implementation for Linux and Unix environments
- Microsoft Radius server IAS
- Radl, a free Radius server for Windows
- RSA SecurID (challenge/response support for the New-PIN mode)
- WinRadius, Windows Radius server (free for 5 users)
- ZyXEL ZyWALL OTP (One-Time Password for Two-Factor Authentication, Authenex ASAS branded by ZyXEL)

Innovation Award
PHP Programming Innovation award nominee
January 2008
Number 2


Prize: One copy of DWebPro Standard License
Radius is a protocol often used for enabling network access to ISP clients upon authentication.

This class is a pure PHP implementation of Radius protocol client.

It can be used to authenticate and grant users the access to Web resources served by PHP using the same user names and passwords that ISP clients use to have network access.

Manuel Lemos
Picture of André Liechti
  Performance   Level  
Name: André Liechti <contact>
Classes: 9 packages by
Country: Switzerland Switzerland
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Recommendations

Radius login class for php 8
I need a class to authenticate users on a radius server.

Example

<?php

require_once('radius.class.php');

?>
<html>
    <head>
        <title>
            Pure PHP radius class demo
        </title>
    </head>
    <body>
        <?php
       
if ((isset($_POST['user'])) && ('' != trim($_POST['user'])))
        {
           
$radius = new Radius('127.0.0.1', 'secret');

           
$radius->SetNasIpAddress('127.0.0.1'); // Needed for some devices, and not auto_detected if PHP not runned through a web server
            // Enable Debug Mode for the demonstration
           
$radius->SetDebugMode(TRUE);

            if (
$radius->AccessRequest($_POST['user'], $_POST['pass']))
            {
                echo
"<strong>Authentication accepted.</strong>";
            }
            else
            {
                echo
"<strong>Authentication rejected.</strong>";
            }
            echo
"<br />";

            echo
"<br /><strong>GetReadableReceivedAttributes</strong><br />";
            echo
$radius->GetReadableReceivedAttributes();

            echo
"<br />";
            echo
"<a href=\"".$_SERVER['PHP_SELF']."\">Reload authentication form</a>";
        }
        else
        {
           
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                User: <input name="user" type="text" value="user" />
                <br />

                Pass: <input name="pass" type="text" value="pass" /> (text type for educational purpose only) <!-- type="text" for educational purpose only ! -->
                <br />
               
                <input name="submit" type="submit" value="Check authentication" />
            </form>
            <?php
       
}
       
?>
</body>
<html>


Details

Pure PHP radius class

This current build (1.2.4) is obsolete. Take a look at the project https://github.com/dapphp/radius, which is based on this work and has been greatly enhanced by Drew Phillips (still maintained).

This Radius class is a radius client implementation in pure PHP following the RFC 2865 rules (http://www.ietf.org/rfc/rfc2865.txt)

(c) 2008-2009 SysCo systemes de communication sa http://developer.sysco.ch/php/

Current build: 1.2.4 (2018-11-03)

Donate via PayPal Please consider supporting this project by making a donation via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&currency_code=USD&business=paypal@sysco.ch&item_name=Donation%20for%20PHP%20radius%20class%20project

This class works with at least the following RADIUS servers: - Authenex Strong Authentication System (ASAS) with two-factor authentication - FreeRADIUS, a free Radius server implementation for Linux and *nix environments - Microsoft Radius server IAS - Mideye RADIUS server (http://www.mideye.com) - Radl, a free Radius server for Windows - RSA SecurID - VASCO Middleware 3.0 server - WinRadius, Windows Radius server (free for 5 users) - ZyXEL ZyWALL OTP (Authenex ASAS branded by ZyXEL, cheaper)

USAGE

require_once('radius.class.php');
$radius = new Radius($ip_radius_server = 'radius_server_ip_address', $shared_secret = 'radius_shared_secret'[, $radius_suffix = 'optional_radius_suffix'[, $udp_timeout = udp_timeout_in_seconds[, $authentication_port = 1812]]]);
$result = $radius->Access_Request($username = 'username', $password = 'password'[, $udp_timeout = udp_timeout_in_seconds]);

EXAMPLES

Example 1

    require_once('radius.class.php');
    $radius = new Radius('127.0.0.1', 'secret');
    $radius->SetNasIpAddress('1.2.3.4'); // Needed for some devices (not always auto-detected)
    if ($radius->AccessRequest('user', 'pass')) {
        echo "Authentication accepted.";
    } else {
        echo "Authentication rejected.";
    }

Example 2

    require_once('radius.class.php');
    $radius = new Radius('127.0.0.1', 'secret');
    $radius->SetNasPort(0);
    $radius->SetNasIpAddress('1.2.3.4'); // Needed for some devices (not always auto-detected)
    if ($radius->AccessRequest('user', 'pass')) {
        echo "Authentication accepted.";
        echo "<br />";
    } else {
        echo "Authentication rejected.";
        echo "<br />";
    }
    echo $radius->GetReadableReceivedAttributes();

  Files folder image Files (8)  
File Role Description
Plain text file radius.class.php Class Main file, class definition
Accessible without login Plain text file radius.www.authenticate.php Appl. Additional file to implement WWW Authentication using a Radius server
Accessible without login Plain text file radius.demo.php Example Demo file for regular usage
Accessible without login Plain text file radius.demo.www.authenticate.php Example Demo of a WWW Authentication using a Radius server
Accessible without login Plain text file radius.challenge.response.demo.php Example Challenge/response demo file
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file COPYING.LESSER Lic. LGPL Version 3.0
Accessible without login Plain text file COPYING Lic. GPL Version 3.0

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:2,272
This week:0
All time:1,716
This week:41Up
User Ratings User Comments (2)
 All time
Utility:94%StarStarStarStarStar
Consistency:88%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:86%StarStarStarStarStar
Tests:-
Videos:-
Overall:72%StarStarStarStar
Rank:193
 
This was a great example, and as of 10/21/2015 this still is ...
8 years ago (David Kittell)
80%StarStarStarStarStar
saves me hours!
13 years ago (Thomas Ehrhardt)
80%StarStarStarStarStar