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 http://atat.ro/utile/short-url/

The code:

function bitly($url) {
	$username = 'username'; // your bitly account
	$api = 'api key'; // your bitly password
	return getContent("http://api.bit.ly/v3/shorten?format=txt&longUrl=$url&login=$username&apiKey=$api");

function tinyurl($url) {
	return getContent("http://tinyurl.com/api-create.php?url=$url");

function google($url) {
	$data = getContent("http://ggl-shortener.appspot.com/?url=$url");
	$json = json_decode($data);

    return $json->short_url;

function isgd($url) {
	return getContent("http://is.gd/api.php?longurl=$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="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>

<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></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>Bit.ly</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>Is.gd</strong> <span id="isgd" class="result"></span></p>

		Created by Rilwis. <a href="http://www.deluxeblogtips.com/2010/06/multiple-url-shortener-page.html">Return to article</a>.
</div> <!-- #container -->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

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

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

7 Years
Discussion Span
Last Post by Reza_3

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";



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 : http://atat.ro/utile/short-url/ (changed the location again). Firefox works fine, though.

Edited by wattaman: n/a


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 www.be.cm

  • 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. http://www.be.cm/url+
  • 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 be.cm to your browser's toolbar

Please feel free and feedback me

Edited by Reza_3: typo

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.