Duplicate connection is created on a Jabber Openfire server

I have created an application in which on the page load Its used to create the session with the openfire server and when again the new page is clicked then also the another duplicate connection is created…and its keep on populating…What i did is

First i made a connection using

function makeconnection(){

      var conn = new Strophe.Connection("[http://192.168.1.18:7070/http-bind/](http://192.168.1.18:7070/http-bind/)");

          conn.connect("<?php echo $user_xmpp_name[0].'@quikr.com'; ?>", "quikr123", function (status) {

if (status === Strophe.Status.CONNECTED) {

Gab.connection = conn;

//Store the connection in Cookie.

Q.cookies.set(‘strophe_conn’, Gab.connection.rid);

Q(document).trigger(“connected”);

}

});

}

Then used to check for the presence of the user using the following Code

Q.ajax({

type: “GET”,

url: “getstatus”,

data: “jid= &type=text”,

dataType: “text”,

success: function(data){

data = Q.trim(data);

if(data == “OFFLINE”){

makeconnection();

} else{

                                            Gab.connection = new Strophe.Connection("[http://192.168.1.18:7070/http-bind/](http://192.168.1.18:7070/http-bind/)");

var stored_conn = Q.cookies.get(‘strophe_conn’);

Gab.connection.rid = stored_conn;

if(!stored_conn){

makeconnection();

}

}

}

});

It checks the status of the User and if user is logged in then we used to extract the Resource ID from the stored cookie and then send the message in case user is not logged in to openfire server then it calls the makeconnection function…and sets the cookie…But when we load the page by clicking another page No Duplicate connection is created but still we cannot exchange the message as its not working or it works for somethime then again stops working please provide me the help regarding this…

Thanks in advance