Sidebar Ad

Categories

Create A TinyUrl Using API in PHP

TinyURL is one of the best and popular free link shortner available since year 2002. It is widely used because it do not show advertisement in its shortened link. TinyURL provide API which can be used by developers and can be implemented in many languages.

Using TinyURL API

http://tinyurl.com/api-create.php?url=techreveal.net

 

Browse this code in your web browser will return you the tinyurl link. Replace techreveal.net with your desired address to short that link using tinyurl api

Using TinyURL API In PHP File

By using tinyurl api in php file , you can take the link to be shortened by users in real time.For this you need two files, one will be a HTML file where users can put their link in textbox and second will be PHP file where the api will be executed. For executing php file, you need a web server.

Coding The Files

HTML Code : // index.html

<html>
<head>
<title>TinyURL Api</title>
</head>
<body>
<h2 align='center'>Short Link Using TinyURL Api</h2><br>
<form method="post" action="short.php">
<center>
<p>Enter Link</p> 
<input type="text" name="url"><br><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</center>
</form>
</body>
<html>

Output

Understanding the code

In this html code , we have taken a textbox in which users will put their link and click on Submit button to short the link. Submit button will be calling ‘short.php’ file in which api of tinyurl will be called.

PHP Code : // short.php

<html>
<head>
<title>TinyURL Api</title>
</head>
<body>

<h2 align='center'>Short Link Using TinyURL Api</h2>


<form method="post" action="short.php">
<center>


Enter Link

 
<input type="text" name="url">

<input type="submit" value="Submit">
<input type="reset" value="Reset">
<center>
</form>



<iframe src="http://tinyurl.com/api-create.php?url=<?php echo $_POST["url"]; ?>"frameborder="0" height="50" width=20% align=middle>


</body>
<html>

Output

Understanding the code

The code is quite similar to index.html file. We have added <iframe> tag in which api is loaded

 

I'm Tech Expert, Programmer , Web Developer, Owner Of this site and much more 😁

    Leave Your Comment

    Your email address will not be published.*