This project is a PHP-native rewrite of the repository abhizaik/phishing-detection.
SafeSurf for PHP focuses on transparent analysis results (reasons), scores, and verdicts.
- Real-time URL analysis: redirect chain, HTTP status, HSTS
- Domain & DNS signals: rank (top-1m), IP resolution, NS/MX validity
- URL signals: keywords, URL shortener, excessive length/depth, subdomain count, punycode
- TLS/SSL signals: TLS presence, issuer, certificate age, chain validation (best effort)
- Page content (best effort): title, login/payment/personal form detection, hidden iframe, brand mismatch
- Threat feed: PhishTank (optional, depending on API availability)
- Optional caching via phpfastcache to speed up network lookups and data parsing
- PHP >= 8.0
- PHP extensions:
curl,openssl,dom,libxml
composer require safesurf/safesurfgit clone https://github.com/DikaArdnt/safesurf-php.git
cd safesurf-php
composer installphp examples/analyze.php example.com<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use SafeSurf\SafeSurf;
$result = SafeSurf::analyze('https://example.com');
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL;<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Phpfastcache\CacheManager;
use Phpfastcache\Config\ConfigurationOption;
use SafeSurf\Cache\PhpFastCacheAdapter;
use SafeSurf\Config;
use SafeSurf\SafeSurf;
$pool = CacheManager::getInstance('Files', new ConfigurationOption([
'path' => __DIR__ . '/storage/cache',
]));
$config = new Config(cache: new PhpFastCacheAdapter($pool));
$result = SafeSurf::analyze('https://example.com', $config);
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL;The main configuration is located in Config.php. The most commonly used fields are:
cache: cache implementation (optional). Ready-to-use adapter: PhpFastCacheAdapter.phprankCsvPath: path toassets/top-1m.csvfor rank lookuppublicSuffixListPath: PSL path (storage/public_suffix_list.dat), used to extract the registrable domain and TLDhttpTimeoutMs,httpHeaderTimeoutMs,maxRedirects,userAgent: HTTP request controls- Cache TTLs:
ttlDomainRankSeconds,ttlIpResolutionSeconds,ttlDnsValiditySeconds,ttlWhoisSeconds,ttlHttpCombinedSeconds,ttlTlsCombinedSeconds,ttlContentSeconds,ttlAnalyzeResultSeconds - PhishTank (optional):
phishTankApiKey,phishTankUserAgent
SafeSurf::analyze() returns an array that is suitable for json_encode():
url,domainfeaturesranktld:tld,is_trusted_tld,is_risky_tld,is_icannurl:url_shortener,uses_ip,contains_punycode,too_long,too_deep,has_homoglyph,subdomain_count,keywords
infrastructure:ip_addresses,nameservers_valid,ns_hosts,mx_records_valid,mx_hostsdomain_info: RDAP/WHOIS results (may benullif lookup fails)analysis: redirect chain, HTTP status, HSTSssl_infoandtls_info: TLS/SSL summarycontent_data: HTML parsing summary (may benull)domain_randomness: entropy/randomness results for the domain labeltyposquat_result: typosquatting/combo-squatting resultsphishing: PhishTank check results (may benull)result: final score, verdict, and reasonsperformance: total time and timing listincomplete,errors: present if some tasks fail (network/timeouts)
- SSRF protection: HTTP requests resolve IPs and reject private, link-local, and loopback IPs for target hosts/IPs.
- TLS/SSL validation is best effort: some environments may fail to verify the chain due to CA store or configuration issues.
- Some modules require internet access (IANA RDAP bootstrap, PSL download, PhishTank).
- Content analysis performs GET requests and HTML parsing; enable caching to reduce load.
Run tests:
cd safesurf-php
vendor/bin/phpunitMIT License. See LICENSE for details.