1. Go to this page and download the library: Download joshghent/loginllama library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joshghent / loginllama example snippets
LoginLlama\LoginLlama;
$loginllama = new LoginLlama('your-api-key');
// IP and User-Agent are automatically detected from $_SERVER!
$result = $loginllama->check($_POST['email']);
if ($result['status'] === 'error' || $result['risk_score'] > 5) {
error_log('Suspicious login blocked: ' . implode(', ', $result['codes']));
http_response_code(403);
echo json_encode(['error' => 'Login blocked']);
exit;
}
// Continue with login...
echo json_encode(['success' => true]);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use LoginLlama\LoginLlama;
class LoginLlamaMiddleware
{
private LoginLlama $loginllama;
public function __construct()
{
$this->loginllama = new LoginLlama(env('LOGINLLAMA_API_KEY'));
}
public function handle(Request $request, Closure $next)
{
$middleware = $this->loginllama->middleware();
$middleware($request);
return $next($request);
}
}
namespace App\EventSubscriber;
use LoginLlama\LoginLlama;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LoginLlamaSubscriber implements EventSubscriberInterface
{
private LoginLlama $loginllama;
public function __construct()
{
$this->loginllama = new LoginLlama($_ENV['LOGINLLAMA_API_KEY']);
}
public function onKernelRequest(RequestEvent $event): void
{
$middleware = $this->loginllama->middleware();
$middleware($event->getRequest());
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => 'onKernelRequest',
];
}
}
use LoginLlama\LoginCheckStatus;
// Example status codes:
LoginCheckStatus::VALID
LoginCheckStatus::IP_ADDRESS_SUSPICIOUS
LoginCheckStatus::KNOWN_BOT
LoginCheckStatus::GEO_IMPOSSIBLE_TRAVEL
LoginCheckStatus::USER_AGENT_SUSPICIOUS
// ... and more
use LoginLlama\LoginLlama;
$loginllama = new LoginLlama('your-api-key');
try {
$result = $loginllama->check('[email protected]');
} catch (\Exception $e) {
if (str_contains($e->getMessage(), 'IP address could not be detected')) {
// No IP available - pass ipAddress or request explicitly
}
error_log('LoginLlama error: ' . $e->getMessage());
}