Skip to content

LinkShrink — PHP URL Shortener with Click Stats

1 downloads 9 views Updated 3 hours ago
LinkShrink — PHP URL Shortener with Click Stats
Price
Free
No cost
Downloads
1
Category
PHP Scripts
Last update
Oct 24, 2026
License
MIT / Free use
Reviewed by our team before publishing

About this code

LinkShrink — PHP URL Shortener with Click Stats

Turn long, ugly URLs into clean short links — and see exactly how many people click them. LinkShrink is a complete, self-hosted URL shortener written in plain PHP: paste a link, get a short URL like yoursite.com/r/aB3xQ9, and every click is logged with a per-day breakdown on the stats dashboard.

No database to configure, no API keys, no monthly fees — your own private bit.ly running on any cheap shared hosting.

Features

  • Instant short links — auto-generated 6-character codes, or set your own custom alias (e.g. /r/diwali-offer) for branding.
  • Click stats dashboard — totals + searchable table of every link, with a per-day click breakdown on each link's detail view.
  • Smart duplicate detection — shortening the same URL twice returns the existing short link instead of cluttering your database.
  • 301 permanent redirects — SEO-friendly redirects via clean /r/CODE URLs (pretty URLs through .htaccess).
  • One-click copy + delete — copy button with clipboard fallback, and delete any link (with its click history) from the stats page.
  • Zero-config SQLite storage — database is created automatically on first run; no MySQL setup, perfect for shared hosting.
  • Security built in — URL validation (http/https only), PDO prepared statements, HTML-escaped output, CSRF tokens, and per-IP rate limiting.

What's Inside

  • index.php — Home page with the shorten form + copy-to-clipboard result box
  • r.php — Redirect handler: logs the click and issues the 301 redirect
  • stats.php — Stats dashboard: totals, searchable link table, per-day detail view, delete
  • lib/app.php — Database layer, helpers, CSRF protection, rate limiting
  • assets/style.css — Dark, mobile-responsive theme (vanilla CSS, no build step)
  • .htaccess — Pretty /r/CODE short URLs
  • data/ — SQLite database folder (auto-created, web access blocked)
  • README.txt — 1-minute setup guide

Requirements

  • PHP 7.4 or newer
  • pdo_sqlite extension enabled (standard on most shared hosts)
  • mod_rewrite for pretty /r/CODE URLs (optional — r.php?c=CODE works without it)

1-Minute Setup

  1. Upload the files to your web host.
  2. Open your site in a browser — the database is created automatically.
  3. Paste a long URL, get a short link, share it. Done!

FAQ

Do I need to create a MySQL database?
No. LinkShrink uses SQLite — the database file is created automatically on first run. Nothing to configure.

Will it work on cheap shared hosting?
Yes — that's what it was built for. Any host with PHP 7.4+ and pdo_sqlite works. Upload and open.

Can I use my own custom short links?
Yes. Enter any alias (3–30 characters, letters/digits/dash/underscore) when shortening, e.g. yoursite.com/r/my-offer.

Is the click data mine?
100%. Everything is stored in your own SQLite file — no third party, no tracking pixels, no subscriptions.

Need a Custom Website or Mobile App?

Downloading free code is just the start. Yadu Tech builds complete websites and mobile apps for businesses — design, development, deployment, all done for you.

👉 Chat on WhatsApp

Features & includes

Full source code
Easy setup
Clean, modular code
Responsive design

You might also like

More in PHP Scripts
InvoicePro — GST Invoice & Client Management System (PHP + MySQL)
Premium
PHP Scripts • 5d ago

InvoicePro — GST Invoice & Client Management System (PHP + MySQL)

InvoicePro — GST Invoice & Client Management System (PHP + MySQL) A complete, ready-to-deploy invoicing system for Indian small businesses,...

1 49
₹399
SnapGallery — PHP Image Gallery with Lightbox, Upload & Admin
Free
PHP Scripts • 5d ago

SnapGallery — PHP Image Gallery with Lightbox, Upload & Admin

SnapGallery — PHP Image Gallery with Lightbox, Upload & Admin A small, self-contained PHP photo gallery script — upload photos with drag & d...

2 37
Free
AuthKit PHP — Secure Login & Signup System with bcrypt, CSRF & Session Protection
Free
PHP Scripts • 1w ago

AuthKit PHP — Secure Login & Signup System with bcrypt, CSRF & Session Protection

AuthKit PHP — Secure Login & Signup System A complete, self-contained user authentication system in pure PHP: signup + login + protected das...

1 70
Free
LinkShrink — PHP URL Shortener with Click Stats
Free
Download