Posts Tagged ‘PHP’

Best PHP Frameworks 2013

PHP Frameworks provides architecture (MVC) to create applications. It helps to speed up application development process.
After reading the views of many programmers, I made a conclusion that none of the PHP Frameworks satisfies all the programmers/applications needs.

Each Framework has its own features and it should be chosen as per the needs. Like some are good for small application while some are best suited for large. You should check their database support, community support and documentation while choosing one.

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.


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’

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:

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

echo checkConnection();

Username availability check using PHP and jQuery

It’s always good to check the username or email for availability before submission. So the user can check it instantly and helps them to enter the valid one.

This can be done using PHP and jQuery. Just a little code will do the rest.

Script used:

<script src="" type="text/javascript"></script>
<script type="text/javascript">
function checkUserName(usercheck)
	$('#usercheck').html('<img src="images/ajax-loader.gif" />');
	$.post("checkuser.php", {user_name: usercheck} , function(data)
			   if (data != '' || data != undefined || data != null) 

The CSS used:

font-family:"Trebuchet Ms";
color: #FF0000;
color: #33CC00;

The HTML page:

<div style="padding:100px 0px  50px 10px;">
Username : <input type="text" name="username" id="username" onblur="checkUserName(this.value)" /> 
<span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span>

The PHP (processing) page:

$arr_user=array("itechroom", "trialuser");
{echo '<span class="error">Username already exists.</span>';exit;}
else if(strlen($username) < 6 || strlen($username) > 15){echo '<span class="error">Username must be 6 to 15 characters</span>';}
else if (preg_match("/^[a-zA-Z1-9]+$/", $username)) 
       echo '<span class="success">Username is available.</span>';
      echo '<span class="error">Use alphanumeric characters only.</span>';

View Demo Download

Powered by WordPress