Skip to content

Simple library to check an IP address against a domain's SPF record

License

Notifications You must be signed in to change notification settings

Mika56/PHP-SPF-Check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-SPF-Check

CI Latest Stable Version Total Downloads License Codacy Badge Codacy Badge

Simple library to check an IP address against a domain's SPF record

Requirements

This library requires a supported version of PHP, that is PHP 7.4 and >= 8.0.

If you are running an older version of PHP, you might be interested in the version 1 of this library, working with PHP version as old as 5.3. Please note that this version does not have all features and will not receive any bugfixes.

Installation

This library is available through Composer. Run composer require "mika56/spfcheck:^2.0" or add this to your composer.json:

{
  "require": {
    "mika56/spfcheck": "^2.0"
  }
}

Usage

Create a new instance of SPFCheck. The constructor requires a DNSRecordGetterInterface to be passed. Included in this library is DNSRecordGetter, which uses PHP's DNS function dns_get_record to get data. Please take a look at mika56/spfcheck-dns-direct if you want to use custom DNS servers.

<?php
use Mika56\SPFCheck\DNS\DNSRecordGetter;
use Mika56\SPFCheck\SPFCheck;

require('vendor/autoload.php');

$checker = new SPFCheck(new DNSRecordGetter());
var_dump($checker->getIPStringResult('127.0.0.1', 'test.com'));

Return value is one of Result::SHORT_PASS, Result::SHORT_FAIL, Result::SHORT_SOFTFAIL, Result::SHORT_NEUTRAL, Result::SHORT_NONE, Result::SHORT_PERMERROR, Result::SHORT_TEMPERROR

If you want to get more details about the check, you can use SPFCheck::getResult(Query $query): Result which will return a Result object with more details about the check.

About

Simple library to check an IP address against a domain's SPF record

Topics

Resources

License

Stars

Watchers

Forks

Languages