TutorialsIntegrate GDShine with an External PHP Site (Hide Drive URLs)
advancedadvanced

Integrate GDShine with an External PHP Site (Hide Drive URLs)

Drop-in PHP helper that swaps Google Drive URLs for GDShine share URLs in download buttons. 10-minute install.

7 min read7 steps
1

Get an API key + add your domain as origin

Go to /dashboard/api-keys and generate a key. Name it after your site (e.g., mysite.com).

Add your domain to Allowed Origins — this locks the key to your site. Even if it leaks, attackers can't reuse it.

Copy the key — store it as a constant in your PHP code or an environment variable.

2

Download gdshine.php

Grab the helper file from the API docs and save it to your site root. It's ~100 lines of PHP with two public functions:

  • gdshineShareUrl($driveUrl) — returns the GDShine share URL for a given Drive URL, or null on failure
  • gdshineLink($driveUrl, $label, $cssClass) — returns a ready-to-echo <a> tag, or a disabled span on failure

Set GDSHINE_API_KEY at the top of the file to your key.

3

Send the Referer header (important for server-side calls)

Because PHP cURL doesn't send Origin/Referer by default, the origin allowlist will reject your server-side calls. Add this to the cURL setup inside gdshineShareUrl():

CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'X-API-Key: ' . GDSHINE_API_KEY,
    'Referer: https://mysite.com/',  // <-- your domain
    'Origin: https://mysite.com',
],

Now GDShine's origin check passes the same way it would for a browser request.

4

Replace your Drive link output

Find where your PHP code currently outputs a raw Drive URL, for example:

echo '<a href="' . $url . '" class="btn btn-primary">Download</a>';

Replace with:

require_once __DIR__ . '/gdshine.php';
echo gdshineLink($url, 'Download', 'btn btn-primary');

That's it. The rendered HTML now has a gdshine.org/s/... URL instead of drive.google.com/....

5

How the caching works

The helper caches each Drive-URL → GDShine-URL mapping in a local file (keyed by sha1 of the URL) with a 30-day TTL.

First visit to a page: GDShine API is called, result cached.
Visit 2-10,000: served from disk cache, zero API calls.

This keeps your API usage low and page loads fast (no network call for cached URLs).

Cache directory: ./cache/gdshine/ (auto-created). Clear manually with gdshineClearCache() or rm -rf cache/gdshine/*.

6

Test the integration

Load any page that outputs a Drive download button. Right-click → View Page Source.

  • Search for drive.google.com → should be zero matches
  • Search for gdshine.org/s/ → should find your download button's href

Then back in the GDShine dashboard, open /dashboard/api-keys and expand the key. You should see 201 (success) calls in the recent activity panel.

7

WordPress version (bonus)

For WordPress, create a shortcode in functions.php:

add_shortcode('gdrive', function($atts) {
    require_once __DIR__ . '/gdshine.php';
    return gdshineLink(
        $atts['url'],
        $atts['label'] ?? 'Download',
        'wp-block-button__link'
    );
});

Then in any post: [gdrive url="https://drive.google.com/file/d/ABC/view" label="Download PDF"]. Clean button, no Drive URL exposed.

You're done!

You've completed all 7 steps. Questions? Reach out to support.