Search by

copyleaks / php-plagiarism-checker

Copyleaksaihamramicopyleaksshadiawidat

The official Copyleaks PHP SDK. Copyleaks is the integrity layer for your tech stack that helps organizations and individuals understand what's human-made and original, AI-generated, or manipulated across text, image, audio and video. This SDK covers AI Text Detection, AI Image Detection, Plagiarism

Package info

github.com/Copyleaks/PHP-Plagiarism-Checker

Homepage

pkg:composer/copyleaks/php-plagiarism-checker

Statistics

Installs: 78 315

Dependents: 0

Suggesters: 0

Stars: 50

Open Issues: 3


README

The official Copyleaks PHP library, supporting PHP versions >=7.4.0.

Copyleaks is the integrity layer for your tech stack that helps organizations and individuals understand what's human-made and original, AI-generated, or manipulated across text, image, audio and video.

This SDK gives you access to the following Copyleaks products:

  • AI Text Detection
  • AI Image Detection
  • Plagiarism Checker (Authenticity scans: file, URL, OCR)
  • Grammar Checker
  • Text Moderation

πŸš€ Getting Started

Before you start, ensure you have the following:

Once you have your account and API key:

Install the SDK:

Install using Packagist

composer require copyleaks/copyleaks

This package was previously published as copyleaks/php-plagiarism-checker. To switch, run composer remove copyleaks/php-plagiarism-checker && composer require copyleaks/copyleaks. The Copyleaks\ namespace is unchanged.

πŸ“š Documentation

To learn more about how to use Copyleaks API please check out our Documentation.

πŸ’‘ Usage Examples

Here are some common usage examples for the Copyleaks SDK. You can also see a comprehensive code example in the demo.php file on our GitHub repository: demo.php.

Get Authentication Token

This example demonstrates how to log in to the Copyleaks API and obtain an authentication token.

<?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}';
    // --------------------

    // Log in to the Copyleaks API
    echo "Authenticating...\n";
    $copyleaks = new Copyleaks();
    $loginToken = $copyleaks->login($EMAIL_ADDRESS, $KEY);
    echo "βœ… Logged in successfully!\n";

For a detailed understanding of the authentication process, refer to the Copyleaks Login Endpoint Documentation.

Submit Text for Plagiarism Scan

This example shows how to prepare and submit raw text content for a plagiarism scan.

<?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}';
    // --------------------

    // 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";

For a full guide please refer to our step by step Guide

For a detailed understanding of the plagiarism detection process, refer to the Copyleaks Submit Endpoint Documentation

Reading the AI alert from the completed webhook

When a scan submitted with AI detection (aiGeneratedText.detect) finds AI-generated text, the completed webhook carries a suspected-ai-text alert. Its additionalData is the AI detection result encoded as a JSON string, which the SDK decodes for you.

<?php

    require_once(__DIR__ . '/vendor/autoload.php');

    use Copyleaks\CompletedWebhook;

    // In your handler for the 'completed' webhook
    $webhook = CompletedWebhook::fromArray(json_decode(file_get_contents('php://input'), true));

    $aiAlert = $webhook->getAIDetectionAlert(); // null when the scan produced no AI alert
    if ($aiAlert !== null) {
        try {
            // null when the alert has no data; throws \JsonException when the data is not valid JSON
            $aiResult = $aiAlert->getAIDetectionResult();
            if ($aiResult !== null && $aiResult->summary !== null) {
                error_log("Model " . $aiResult->modelVersion . ": AI " . $aiResult->summary->ai . ", human " . $aiResult->summary->human);
                foreach ($aiResult->results as $result) {
                    error_log("Segment classification: " . $result->classification); // 1 = human, 2 = AI
                }
            }
        } catch (\JsonException $e) {
            error_log("Could not decode the AI alert: " . $e->getMessage());
        }
    }

    // Acknowledge the webhook even when the AI alert could not be decoded.
    http_response_code(200);

getAIDetectionAlert() returns null when the completed webhook contains no suspected-ai-text alert. The raw JSON string stays available in $aiAlert->additionalData.

AI-Generated Text Detection

Use the AI detection client to determine if content was generated by artificial intelligence.

<?php

    require_once(__DIR__ . '/vendor/autoload.php');

    use Copyleaks\Copyleaks;
    use Copyleaks\CopyleaksNaturalLanguageSubmissionModel;

    // --- Your Credentials ---
    $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    $KEY = 'YOUR_API_KEY';
    // --------------------

    $sampleText = "Lions are social animals, living in groups called prides, typically consisting of several females, their offspring, and a few males. Female lions are the primary hunters, working together to catch prey. Lions are known for their strength, teamwork, and complex social structures.";

    $submission = new CopyleaksNaturalLanguageSubmissionModel(
      $sampleText,
    );
    $submission->sandbox = true;

    $response = $this->copyleaks->aiDetectionClient->submitNaturalLanguage($authToken, time(), $submission);
    $this->logInfo('AI Detection - submitNaturalLanguage', $response);

Grammar Checker (WritingAssistantClient)

Get intelligent suggestions for improving grammar, spelling, style, and overall writing quality.

<?php

    require_once(__DIR__ . '/vendor/autoload.php');

    use Copyleaks\Copyleaks;
    use Copyleaks\CopyleaksWritingAssistantSubmissionModel;
    use Copyleaks\ScoreWeights;
    // --- Your Credentials ---
    $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    $KEY = 'YOUR_API_KEY';
    // --------------------

    $sampleText = "Lions are the only cat that live in groups, called pride. A prides typically consists of a few adult males, several feales, and their offspring. This social structure is essential for hunting and raising young cubs. Female lions, or lionesses are the primary hunters of the prid. They work together in cordinated groups to take down prey usually targeting large herbiores like zbras, wildebeest and buffalo. Their teamwork and strategy during hunts highlight the intelligence and coperation that are key to their survival.";

    $scoreWeights = new ScoreWeights(
      0.1, 0.2, 0.3, 0.4
    );

    $submission = new CopyleaksWritingAssistantSubmissionModel(
      $sampleText,
    );

    $submission->sandbox = true;
    $submission->score = $scoreWeights;

    $response = $this->copyleaks->writingAssistantClient->submitText($authToken, time(), $submission);
    $this->logInfo('Writing Assistant - submitText', $response);

For a full guide please refer to our step by step Guide

For a detailed understanding of the Grammar Checker (WritingAssistantClient) process, refer to the Copyleaks writing feedback Endpoint Documentation

Text Moderation

Scan and moderate text content for unsafe, inappropriate, or policy-violating material across various categories.

<?php

    require_once(__DIR__ . '/vendor/autoload.php');

    use Copyleaks\Copyleaks;
    use Copyleaks\CopyleaksTextModerationRequestModel;
    use Copyleaks\CopyleaksTextModerationConstants;
    use Copyleaks\CopyleaksTextModerationLanguages;
    use Copyleaks\CopyleaksTextModerationResponseModel;
    // --- Your Credentials ---
    $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    $KEY = 'YOUR_API_KEY';
    // --------------------

    $labelsArray=[
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::ADULT_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::TOXIC_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::VIOLENT_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::PROFANITY_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::SELF_HARM_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::HARASSMENT_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::HATE_SPEECH_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::DRUGS_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::FIREARMS_V1),
        new CopyleaksTextModerationLabel(CopyleaksTextModerationConstants::CYBERSECURITY_V1)
    ]; // labels

     $textModerationRequest = new CopyleaksTextModerationRequestModel(
      "This is some text to scan.", // text
      true,                        // sandbox mode
      CopyleaksTextModerationLanguages::ENGLISH, // language
      $labelsArray
      );

    $response = $this->copyleaks->textModerationClient->submitText($authToken, time(), $model);
    $textModerationResponse= CopyleaksTextModerationResponseModel::fromArray(json_decode(json_encode($response), true));

    $this->logInfo('Text Moderation - submitText', $textModerationResponse);

For a full guide please refer to our step by step Guide

For a detailed understanding of the Text moderation process, refer to the Copyleaks text moderation Endpoint Documentation

AI Image Detection

Determine if a given image was generated or partially generated by an AI.

    <?php
    require_once(__DIR__ . '/vendor/autoload.php');

    use Copyleaks\Copyleaks;
    use Copyleaks\CopyleaksAuthToken;
    use Copyleaks\CopyleaksAiImageDetectionRequestModel;
    use Copyleaks\CopyleaksAiImageDetectionResponseModel;
    use Copyleaks\CopyleaksAiImageDetectionModels;
    // --- Your Credentials ---
    $EMAIL_ADDRESS = 'YOUR_EMAIL_ADDRESS';
    $KEY = 'YOUR_API_KEY';
    // --

    // Read and encode your image file to base64
    $imagePath = "path/to/your/image.jpg"; // Update this path to your actual image file
    
    $base64Image = base64_encode(file_get_contents($imagePath));
    $fileName = basename($imagePath);
    
    $submission = new CopyleaksAiImageDetectionRequestModel(
        $base64Image,
        $fileName,
        CopyleaksAiImageDetectionModels::AI_IMAGE_1_ULTRA,
        true // Use sandbox mode for testing
    );

    $response = $copyleaks->aiImageDetectionClient->submit($authToken, time(), $submission);
    $imageDetectionResponse = CopyleaksAiImageDetectionResponseModel::fromArray(json_decode(json_encode($response), true));

For a full guide please refer to our step by step Guide

For a detailed understanding of the AI Image Detection process, refer to the Copyleaks AI image detection Endpoint Documentation

Further Resources

  • Copyleaks API Dashboard: Manage your API keys, monitor usage, and view analytics from your personalized dashboard. Access Dashboard
  • Copyleaks SDK Documentation: Explore comprehensive guides, API references, and code examples for seamless integration. Read Documentation

Support

  • If you need assistance, please contact Copyleaks Support via our support portal: Contact Copyleaks Support.
  • To arrange a product demonstration, book a demo here: Booking Link.