SSL certificate problem: unable to get local issuer certificate

Website URL

https://supergamer474.rf.gd/tools/html-url
cURL link: https://short-links.rf.gd (Specifically https://short-links.rf.gd/create.php?long-url=base64-encoded-url&custom-ending=custom)

Error Message

Error while shortening the URL: SSL certificate problem: unable to get local issuer certificate

Other Information

html-url.php

<?php
// Allow requests from any origin
header("Access-Control-Allow-Origin: *");

// Optional: Allow specific HTTP methods (GET, POST, etc.)
header("Access-Control-Allow-Methods: GET, POST");

// Optional: Allow specific headers
header("Access-Control-Allow-Headers: Content-Type, Authorization");

// Optional: For preflight requests (OPTIONS method)
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
    header("HTTP/1.1 200 OK");
    exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML to URL Converter</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f2f5;
            color: #333;
        }

        header {
            background-color: #1a73e8;
            padding: 20px;
            text-align: center;
            color: white;
        }

        h1 {
            margin: 0;
            font-size: 24px;
        }

        main {
            padding: 40px 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        section {
            width: 100%;
            max-width: 1000px;
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
        }

        textarea, input[type="url"], input[type="file"] {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 5px;
            margin-bottom: 15px;
        }

        input[type="file"] {
            padding: 5px;
        }

        button {
            width: 100%;
            max-width: 300px;
            padding: 12px;
            background-color: #1a73e8;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 18px;
            cursor: pointer;
            margin-top: 20px;
        }

        button:hover {
            background-color: #155bb5;
        }

        .output {
            width: 100%;
            padding: 15px;
            background-color: #e6f4ea;
            border: 1px solid #d4edda;
            border-radius: 5px;
            word-wrap: break-word;
            cursor: pointer;
            font-family: monospace;
        }

        .error {
            color: red;
            margin-top: 10px;
        }
    </style>
</head>
<body>

<header>
    <h1>HTML to URL Converter</h1>
</header>

<main>
    <section>
        <label for="htmlInput">Paste HTML Code:</label>
        <textarea id="htmlInput" rows="6" placeholder="Paste your HTML code here..."></textarea>
    </section>

    <section>
        <label for="fileInput">Upload HTML File:</label>
        <input type="file" id="fileInput" accept=".html">
    </section>

    <section>
        <label for="urlInput">Enter URL:</label>
        <input type="url" id="urlInput" placeholder="Enter URL (e.g., https://example.com)">
    </section>

    <button onclick="generateURL()">Generate Base64 URL (URL Works Offline)</button><br>
    <button onclick="generateAndShorten()">Generate Base64 URL & Shorten (URL Requires Internet)</button><br>

    <div class="output" id="output" onclick="copyToClipboard()">Click to copy Base64 URL</div>

    <div class="error" id="error"></div>
</main>

<script>
async function generateURL() {
    const htmlInput = document.getElementById('htmlInput').value;
    const fileInput = document.getElementById('fileInput').files[0];
    const urlInput = document.getElementById('urlInput').value;
    const output = document.getElementById('output');
    const error = document.getElementById('error');

    output.textContent = '';  // Clear previous output
    error.textContent = '';   // Clear previous errors

    try {
        let base64;
        if (htmlInput) {
            // If HTML code is inputted directly
            base64 = encodeToBase64(htmlInput);
        } else if (fileInput) {
            // If an HTML file is uploaded
            const reader = new FileReader();
            reader.onload = function(event) {
                const content = event.target.result;
                base64 = encodeToBase64(content);
                output.textContent = `data:text/html;base64,${base64}`;
            };
            reader.readAsText(fileInput);
            return; // Ensure we exit early while reading the file
        } else if (urlInput) {
            // Fetch the HTML content from the provided URL
            const response = await fetch(urlInput);
            if (!response.ok) throw new Error('Unable to fetch content. Check the URL.');
            const content = await response.text();
            base64 = encodeToBase64(content);
        } else {
            error.textContent = 'Please enter HTML code, upload a file, or provide a URL.';
            return; // Exit if no input is provided
        }
        
        // Set the output with the generated Base64 URL
        output.textContent = `data:text/html;base64,${base64}`;
    } catch (err) {
        error.textContent = `Error: ${err.message}`;
    }
}

async function generateAndShorten() {
    const output = document.getElementById('output');
    const error = document.getElementById('error');
    const customEnding = prompt("Enter a custom ending for the shortened URL:");

    if (!customEnding) {
        error.textContent = 'Custom ending is required.';
        return;
    }

    // Ensure output contains a valid Base64 URL
    const base64Url = output.textContent;

    // Check if the output starts with 'data:text/html;base64,' and is valid
    if (!base64Url.startsWith('data:text/html;base64,')) {
        error.textContent = 'Please generate a valid Base64 URL first.';
        return;
    }

    try {
        const response = await fetch('generateandshorten.php', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: new URLSearchParams({
                base64Url: base64Url, // Send the entire data URL
                customEnding: customEnding
            }).toString() // Ensures correct format
        });

        if (!response.ok) throw new Error('Error while shortening the URL.');

        const result = await response.text(); // Expect a plain text response

        // Replace &amp; with & in the shortened URL before displaying
        const cleanedUrl = result;
        output.textContent = cleanedUrl;  // Show the shortened URL
    } catch (err) {
        error.textContent = `Error: ${err.message}`;
    }
}

function encodeToBase64(str) {
    return btoa(unescape(encodeURIComponent(str)));
}

function copyToClipboard() {
    const output = document.getElementById('output');
    const range = document.createRange();
    range.selectNode(output);
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(range);
    
    // Copy the highlighted text
    document.execCommand('copy');
    
    // Alert user that the text has been copied
    alert('Copied to clipboard!');
}
</script>

</body>
</html>

generateandshorten.php

<?php

// Allow requests from any origin
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Get data from the POST request
    $base64Url = $_POST['base64Url'] ?? null;
    $customEnding = $_POST['customEnding'] ?? null;

    // Validate input
    if (!$base64Url) {
        echo 'Error: Base64 URL is required';
        exit();
    }

    if (!$customEnding) {
        echo 'Error: Custom ending is required';
        exit();
    }

    // Remove any &amp; from the base64Url and customEnding
    $base64Url = str_replace('&amp;', '&', $base64Url);
    $customEnding = str_replace('&amp;', '&', $customEnding);

    // Construct the full URL for shortening
    $shortenUrl = 'https://short-links.rf.gd/create.php?long-url=' . urlencode($base64Url) . '&custom-ending=' . urlencode($customEnding);

    // Debugging output: Uncomment to see the constructed URL
    // error_log("Shorten URL: " . $shortenUrl);

    // Use curl to fetch the shortened URL
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $shortenUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects if any
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Set a timeout

    $shortenedUrl = curl_exec($ch);
    
    if (curl_errno($ch)) {
        // Capture the error using curl
        echo 'Error while shortening the URL: ' . curl_error($ch);
    } else {
        // Remove HTML tags from the shortened URL response
        $cleanedUrl = strip_tags($shortenedUrl);

        // Return the cleaned shortened URL as a plain string
        echo $cleanedUrl;
    }

    curl_close($ch);
}
?>

Sounds like this

3 Likes

It’s that, but more importantly, it’s this:

Also, please note that URL shorteners are frowned upon on our hosting. Spammers love using URL shorteners to hide their spam/scam content behind other people’s domain names.

I can see how this is a cool project to build and show, but please think very carefully before you want to expose this to the world.

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.