I have created a website and clicnt needs a link shortner to be integrated on the website the link shortner and is of https://po.st they have an API key as well so please let me know how do I integrate the link shortner is there a way using an API key and make a custom link shortner

Thank You

Recommended Answers

All 4 Replies


Thank you for you r response I read it out but how wil i make it on the website like some one comes on the website and can shorten link from there though .
Do I have to create a form ?? Please guide me how do i place the link shortner on the website .

Thank You

Connecting to the REST API is one part, you could do that with PHP and cURL.
There are plenty of tutorials online about using cURL with PHP in conjunction with REST.

Then you'll need to decide how your service/users/whatever interfaces with that feature.

If you need a form for users to be able to make their own, then build a form that collects their data and sends it to the application, and then in turn communicates with the API.

You need to do your own leg work first though, and then come back when you have questions about the code you've already written.

Here is what I tried to make it off I dont know why its not working not sending the shortened links to the crm there though they should have provided a widget where we can easily paste it to our html or php page though.



// Create instance with key
$key = '---';
$googer = new GoogleURLAPI($key);

// Test: Shorten a URL
$shortDWName = $googer->shorten("http://davidwalsh.com");
echo $shortDWName; // returns http://goo.gl/i002

// Test: Expand a URL
$longDWName = $googer->expand($shortDWName);
echo $longDWName; // returns http://davidwalsh.name

// Declare the class
class GoogleUrlApi {

    // Constructor
    function GoogleURLAPI($key,$apiUR = 'http://po.st/api/shorten?longUrl=test&apiKey=---') {
        // Keep the API Url
        $this->apiURL = $apiURL.'?key='.$key;

    // Shorten a URL
    function shorten($url) {
        // Send information along
        $response = $this->send($url);
        // Return the result
        return isset($response['id']) ? $response['id'] : false;

    // Expand a URL
    function expand($url) {
        // Send information along
        $response = $this->send($url,false);
        // Return the result
        return isset($response['longUrl']) ? $response['longUrl'] : false;

    // Send information to Google
    function send($url,$shorten = true) {
        // Create cURL
        $ch = curl_init();
        // If we're shortening a URL...
        if($shorten) {
            curl_setopt($ch, CURLOPT_URL, $this->apiURL);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("longUrl"=>$url)));
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
        else {


        // Execute the post
        $result = curl_exec($ch);

        // Close the connection

        // Return the result
        return json_decode($result,true);

    header("Location: ../coupon.php?id=" . $id . "&code=" . $_SESSION['code']);


 <form method="post" action="includes/linkshort.php">
                    <input type="text" name="link" />
                    <input type="submit" name="submit" />

Thank You

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.