So, I've found this code somewhere on the net (don't remember) and I'm trying to embed it into my site, just in case some of the visitors would need to use it. It creates short URLs (from 4 services) of a particular address.
What I don't understand, and I hope someone could help me, is: why the code works when I test it locally, on my Windows+Xampp computer, but not on the server. The server is a centos 5, apache 2.23, php 5.1. I have suhosin installed, could this restrict the script, somehow!? I'm really lost, don't know what to try. I've chmoded the file in all the possible ways, I've enabled the allow_url_fopen, but still nothing. It doesn't extract/display the results.
Any help and suggestion would be much apreciated.
Thank you!
BTW, the address I'm testing it is

The code:

function bitly($url) {
	$username = 'username'; // your bitly account
	$api = 'api key'; // your bitly password
	return getContent("$url&login=$username&apiKey=$api");

function tinyurl($url) {
	return getContent("$url");

function google($url) {
	$data = getContent("$url");
	$json = json_decode($data);

    return $json->short_url;

function isgd($url) {
	return getContent("$url");

 * Helper function for getting remote content
 * Using cURL or file_get_contents
function getContent($url) {
	$content = '';
	// use cURL
	if (function_exists('curl_init')) {
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		$content = curl_exec($ch);
	// use file_get_contents
	elseif (ini_get('allow_url_fopen')) {
		$content = file_get_contents($url);
	return $content;

if (!empty($_GET['url'])) {
	$url = rawurlencode($_GET['url']);
	$result = array();
	$result['bitly'] = bitly($url);
	$result['tinyurl'] = tinyurl($url);
	$result['google'] = google($url);
	$result['isgd'] = isgd($url);
	echo json_encode($result);
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title>Multiple URL Shortener</title>

<!--[if IE]>
<script src=""></script>

<!--[if lt IE 9]>
<script src=""></script>

/* yui 2 reset */

body{font:13px/1.5em Verdana,Arial,Helvetica,sans-serif;color:#333}
#container{width:500px;margin:30px auto}

header h1{font:italic 30px Georgia,"Times New Roman",Times,serif;color:#888;text-align:center}


input{float:left;border:1px solid #6baff0}
#url{width:350px;height:18px;padding:5px 15px;color:#999;margin-right:10px;-webkit-border-radius:30px;-moz-border-radius:30px;border-radius:30px}

#submit{height:30px;border-top:1px solid #96d1f8;background:#65a9d7;background:-webkit-gradient(linear,left top,left bottom,from(#9ec8f5),to(#65a9d7));background:-moz-linear-gradient(top,#9ec8f5,#65a9d7);padding:5px 10px;-webkit-border-radius:30px;-moz-border-radius:30px;border-radius:30px;color:#fff;font-size:13px;font-family:Helvetica,Arial,Sans-Serif}

#shorturls p{margin-bottom:10px;line-height:1.5em}
#shorturls strong{font-size:18px;font-weight:normal;width:150px;display:inline-block;color:#4096ee}

footer{margin:15px auto}

<div id="container">
		<h1>Multiple URL Shortener</h1>

		<form action="" method="get" id="form">
			<input type="text" name="url" id="url" value="Enter URL here..." onfocus="if(this.value==this.defaultValue)this.value=''" onblur="if(this.value=='')this.value=this.defaultValue" />
			<input type="submit" id="submit" value="Shorten it!" />
		<div id="shorturls">
			<p><strong></strong> <span id="bitly" class="result"></span></p>
			<p><strong>TinyURL</strong> <span id="tinyurl" class="result"></span></p>
			<p><strong>Google</strong> <span id="google" class="result"></span></p>
			<p><strong></strong> <span id="isgd" class="result"></span></p>

		Created by Rilwis. <a href="">Return to article</a>.
</div> <!-- #container -->

<script src=""></script>

	// show loading icon
	$('.result').html('<img src="loading.gif" />');

	var url = $('#url').val();
	$.getJSON('', {url: url}, function(data){
	return false;


Recommended Answers

All 7 Replies

The PHP script is not responding when the JSON request is made.

ie: $.getJSON()

This happens in the client side JS, but your PHP script on the server, will just hang. You'll have to figure out what is hanging. I'm guessing it is the HTTP requests made in the PHP script to the URL shortening services.

Try adding some debugging to your PHP script, like:

function getContent($url) {

echo "calling getContent with URL: $url\n";


I'm affraid I don't understand so good - could you please copy/paste exactly the code you think I should replace?! Also, I've noticed that IE8 will load another page with the $url in the address - trying to get short url for will open the page, after submit,

Thank you!

Anyone else who can help, please?

Well, I feel stupid. but I should write this, just in case someone else is having a similar issue: make sure you have the json extension installed if you plan to use json applications :)

However, is not entirelly solved. It seems that IE8, which unfortunatelly is used by most of my site' visitors, is still opening a new page after I click the submit button. please see at : (changed the location again). Firefox works fine, though.

Sorry, I take it back. It works with IE8, too, only if I enable the ad blocker is not working - therefore, the script is functioning, finally, as it should :)

Hello everyone!
Here is a one of shortest URL shortener websites with below spec:

I introduce you

  • Create short URLs using your memorable custom alias
  • Enter your long URL, then click on "Advanced Options" and enter your Custom Alias.
  • Access the statistic page by adding a "+" to the end of your short link e.g.
  • Generate QR Code for your short URL
  • Share your short URL to Facebook and Twitter
  • Shorten multiple long URLs in one go
  • Complete track of your visitors e.g. works well if integrated in email marketing or links to track specific links
  • Password protected URLs
  • Add description to your short URL
  • Redirect users using the same URL if your have different pages for different countries
  • Referrers
  • Add to your browser's toolbar

Please feel free and feedback me

commented: is the best url shortner.. +0
Be a part of the DaniWeb community

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