Archive for the ‘Web Development’ Category

Installing Memcache on RedHat or CentOS server

Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.

 

Login to Linux Server using root credentials. Use PuTTY/KiTTY to login.

 

Download and Install LibEvent

First make a folder named memcache to download the required setup files:

# mkdir memcache (make directory memcache)

# cd memcache (go to memcache directory)

Memcache requires LibEvent. Go to their site and get the latest version.

http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz (Latest stable version)

OR

http://ftp.redhat.com/pub/redhat/rhel/beta/6/x86_64/os/Packages/libevent-1.4.13-1.el6.x86_64.rpm

 

Simple Contact Us form using jQuery and PHP

Here is a simple contact form which is very essential to get feedback from website. It uses JavaScript validation of input parameters like name, address, phone, email, message etc. It uses jQuery post method to submit the input values such that they will be sent without page refresh.

DEMO DOWNLOAD

Login remember using cookie in PHP

A cookie, also known as a web cookie, browser cookie, and HTTP cookie, is a piece of text stored on a user’s computer by their web browser. A cookie can be used for authentication, storing site preferences, shopping cart contents, the identifier for a server-based session, or anything else that can be accomplished through storing text data.

Cookie can have up to seven parameters but mostly first three are used.

The first 3 parameters are:

1. name:  refers to cookie name e.g. cookname

2. value: refers to cookie value stored in cookie name e.g. $_COOKIE['cookname'] => ‘cookvalue’

Setting Cron Jobs from SSH

First of all get PuTTY/KiTTY – a SSH and telnet client which offers secure data exchange between two connected devices.

1. Open PuTTY/KiTTY

2. Enter the IP Address and Port name of host server.

putty-login

3. Login with username and password.

login as: root
root@xxx.xxx.xxx.xx's password:
Last login: Sun Dec 13 06:28:52 2010 from xx.xxx.xxx.xxx.srvlist.ukfast.net
[root@xxx ~]#

[Note: xxx refers to IP Address format]

4. To list crontab (if already there)

[root@xxx ~]# crontab –l
*   *  *   * *  lynx -source http://www.domain.co.uk/cron.php >/dev/null  2>&1

[Note: The file cron.php is running every minute, tested with ukfast.co.uk hosting]

Check the internet connection using PHP function fsockopen

Here is a simple PHP function to check whether a machine is connected to internet or not. It uses a PHP function  fsockopen which initiates a socket connection to the given hostname at the specified port. If the connection is successful it will return true else false.

PHP code:

<?php
//function to check if the local machine has internet connection
function checkConnection()
{
	//Initiates a socket connection to www.itechroom.com at port 80
	$conn = @fsockopen("www.itechroom.com", 80, $errno, $errstr, 30);
	if ($conn)
	{
		$status = "Connection is OK";
		fclose($conn);
	}
	else
	{
		$status = "NO Connection<br/>\n";
		$status .= "$errstr ($errno)";
	}
	return $status;
}
echo checkConnection();
?>

Show popup message for few seconds using jQuery

We have seen checking username availability using jQuery in earlier post. Here is a slight modification on showing of error/success message. The message will be shown as popup and disappears after few seconds. Using this way we can show the message in more fancy way.
The Javascript Code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function checkUserName(usercheck)
{
	var uname = document.getElementById('username').value;
	$.post("checkuser.php", {user_name: uname} , function(data)
		{
			   if (data != '' || data != undefined || data != null)
			   {
				  $('#usercheck').show();
				  $('#usercheck').html(data);
				  setTimeout("$('#usercheck').hide(); ", 3000); //display message for 3 seconds
			   }
          });
}
function checkUserLogin(user_id)
{
   if (user_id == '' || user_id == undefined || user_id == null)
   {
	  $('#logincheck').show();
	  $('#logincheck').css('color', '#CC0000');
	  $('#logincheck').html('You must be logged in to submit.');
	  setTimeout("$('#logincheck').hide(); ", 3000); //display message for 3 seconds
   }
   else {
   	  document.frmPopMessage.submit();
   }
}
</script>

The CSS Code:

Powered by WordPress

Page optimized by WP Minify WordPress Plugin