Skip to content
Official SDKs

PHP Quickstart Guide

This guide will walk you through installing the official PHP SDK and running your first scan. In just a few minutes, you’ll be able to check content for plagiarism, AI-generated text, and more directly from your PHP application.

🔑 Before you begin

In order to start integrating Copyleaks API, you'll need an account and an API key:

  1. Installation

    First, install the official copyleaks/php-plagiarism-checker package from Packagist into your project using Composer.

    Terminal window
    composer require copyleaks/php-plagiarism-checker
  2. Quick Example: Scan Text

    scan.php
    <?php
    require_once(__DIR__ . '/vendor/autoload.php');
    use Copyleaks\Copyleaks;
    use Copyleaks\CopyleaksFileSubmissionModel;
    use Copyleaks\SubmissionProperties;
    use Copyleaks\SubmissionWebhooks;
    // --- Your Credentials ---
    $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    $KEY = 'YOUR_API_KEY';
    $WEBHOOK_URL = 'https://your-server.com/webhook/{STATUS}';
    // --------------------
    try {
    // Log in to the Copyleaks API
    echo "Authenticating...\n";
    $copyleaks = new Copyleaks();
    $loginToken = $copyleaks->login($EMAIL_ADDRESS, $KEY);
    echo "✅ Logged in successfully!\n";
    // Prepare your content for scanning
    echo "Submitting text for scanning...\n";
    $textToScan = "Hello world, this is a test.";
    $base64Content = base64_encode($textToScan);
    $scanId = time();
    // Configure the scan
    $webhooks = new SubmissionWebhooks($WEBHOOK_URL);
    $properties = new SubmissionProperties($webhooks);
    $properties->setSandbox(true); // Turn on sandbox mode for testing
    $submission = new CopyleaksFileSubmissionModel($base64Content, 'test.txt', $properties);
    // Submit the scan to Copyleaks
    $copyleaks->submitFile($loginToken, $scanId, $submission);
    echo "🚀 Scan submitted successfully! Scan ID: " . $scanId . "\n";
    echo "You will be notified via your webhook when the scan is complete.\n";
    } catch (Exception $e) {
    echo "🛑 An error occurred: " . $e->getMessage() . "\n";
    }
  3. Understanding the Code

    The example code performs four main actions to submit a scan:

    1. Login: It authenticates with your email and API key to get a secure login token, which is required for all subsequent requests.
    2. Prepare Content: It takes a simple string of text and encodes it into Base64 format.
    3. Configure Scan: It creates a SubmissionProperties object containing SubmissionWebhooks to define the scan’s behavior. We enable sandbox mode for safe testing and provide the webhook URL.
    4. Submit for Scanning: It creates a CopyleaksFileSubmissionModel with the content and properties, then sends it to the Copyleaks API. The process is asynchronous; Copyleaks will notify your webhook URL once the scan is complete.

Now that you’ve submitted your first scan, here are some recommended steps: