A smarter way to migrate two cPanel servers

One of our cPanel server was running fine without any problem since an year. Suddenly cPanel started sending me emails saying ‘Possible Hard disk Failure’ . Contacted the datacenter to inquire more about this error and perform a log auditing. Dc advised to take the server offline for full hardware test so we did it. The result wasn’t good.

The datacenter advised to reinstall the OS and cPanel on a new hard disk as soon as possible. However this may cause a minimum of 5 hours downtime. So I’ve decided to keep the existing server online and order a new one.  This way, when the new server is up I could move accounts from the old server to the new server and change the nameserver ips so that there will be zero downtime.

Continue reading “A smarter way to migrate two cPanel servers”

Check username availability using Ajax/JQuery

I’m loving jQuery now. Yesterday when I was designing a registration page for a client, I decided to use jQuery to check the availability of username to develop my skill. Practice makes a man perfect, isn’t it ?

Although the client site requires searching of username on its database, I am not going to include this here as it depends on the php developer.

Demo : Click here

Download: Click here

So, I’ve created a php file, check.php which will accept “username” and output “taken” if the username is already taken.

[php]
<?php
$taken = array( “hello”, “john”, “david”,”jason” );
$username= $_POST[‘username’];
if(in_array($username,$taken))
echo “taken”;
?>

[/php]

Then the jQuery Part

[javascript]
$(function()
{
$(“#submit”).click(function(){

var username = $(“#username”).val() ;
$(“#result”).html(“<img src=loading.gif”);
args = “username=” + username ;
$.ajax({
url : “check.php”,
data: args,
type: “POST”,
success: function(data) {
if ( data == “taken” )
$(“#result”).text(“The username is already taken”).hide().fadeIn(“slow”);
else
$(“#result”).text(“The username is available”).hide().fadeIn(“slow”);
}
});

});
});
[/javascript]

HTML part

[html]
<input type=”text” id=”username” />
<input type=”button” id=”submit” value=”Check Availability” />
<br />
<br />
<p id=”result”/> </p>

[/html]

I’ve also used a loading.gif file to get a good ajax look.!

Please modify it if you want use it for your own purpose !

Cross domain ajax quering with JQuery

For security reasons, we cannot make cross-domain AJAX requests with jQuery. For example, I can’t call the load() method, and pass in ‘google.com’. You may get error message “Access denied” if you try so.

Fortunately, I found a solution for this by searching on google.

Jquery can only post queries within the same domain. So we have to set a proxy between us and the world for this purpose.

Therefore I created a simple php file called api.php

[php]

[/php]

The script above will get the “url” and add it with google.com. The result will be shown using echo.

Now, back to jquery

[javascript]
var dataa = $(“#url”).val();
$.ajax({
url: ‘api.php’,
data: dataa,
success: function(data) {
$(‘#short’).html(“<a target=_blank href=” + data + “>” + data + “</a>”);
}
[/javascript]

You’ll see the output now !

Multiple URL shorter using jQuery

JQuery is simply great ! I’ve started learning jQuery just before two days and I’m very much impressed with its functions and simplicity. Especially when the ajax thing comes.

For developing my skills , I just completed making a simple Short URL system. I’ve managed to add five url shorter sites in this script.

This script will shorten the url that the user inputs and output the shortened url. I haven’t added a theme on this but you can add it if you are planning to use it.

Demo : Click here

Download : Click here

Description

This consists of two files, index.html and api.php.

The jQuery part of the code is as follows

[javascript]
$(function() {
$(“#button”).click(function() {
var url = $(“#url”).val() ;
var provider = $(“#provider”).val() ;
args = “url=” + url + “&provider=” + provider ;
$(‘#short’).html(“Please wait..”);

$.ajax({
url: “api.php”,
data: args,
success: function(data) {
$(‘#short’).html(“” + data + ““);
}
});

});

});
[/javascript]

 

Impressed ? Try it and modify it for your use !