Skip to main content

1. Prerequisites

To follow this guide, you will need to:

2. Install and initialize the Dub PHP SDK

1

Install

To install the Dub PHP SDK, run the following command:
2

Initialize

Initialize the Dub PHP SDK by creating a new instance of the Dub class.
index.php
Let’s create a short link using the Dub PHP SDK.
index.php
Optionally, you can also pass an externalId field which is a unique identifier for the link in your own database to associate it with the link in Dub’s system.
index.php
This will let you easily update the link or retrieve analytics for it later on using the externalId instead of the Dub linkId. Dub PHP SDK provides a method to upsert a link – where an existing link is updated if it exists, or a new link is created if it doesn’t. so you don’t have to worry about checking if the link already exists.
index.php
This way, you won’t have to worry about checking if the link already exists when you’re creating it. Let’s update an existing link using the Dub PHP SDK. You can do that in two ways:
  • Using the link’s linkId in Dub’s system.
  • Using the link’s externalId in your own database (prefixed with ext_).
index.php
Let’s retrieve analytics for a link using the Dub PHP SDK.
index.php

7. Examples

PHP Example

See the full example on GitHub.