HMVC with Codeigniter


HMVC is an evolution of the MVC pattern used for most web applications today. It came about as an answer to the salability problems apparent within applications which used MVC. The solution presented in the JavaWorld web site, July 2000, proposed that the standard Model, View, and Controller triad become layered into a “hierarchy of parent-child MCV layers“. The image below illustrates how this works:

HMVC structure

Key advantages to implementing the HMVC pattern in your development cycle:

  • Modularization: Reduction of dependencies between the disparate parts of the application.
  • Organization: Having a folder for each of the relevant triads makes for a lighter work load.
  • Reusability: By nature of the design it is easy to reuse nearly every piece of code.
  • Extendibility: Makes the application more extensible without sacrificing ease of maintenance.

These advantages will allow you to get M.O.R.E out of your application with less headaches.

Download and Tutorial : https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

NOTE : Need some adjustments on several parts.

Advertisements

NetBeans 7.2 : Dreamweaver in Linux and more.


NB_box72

This is an amazingly powerful tool that equally powerful to work as a platform framework for Java desktop applications and as an IDE (integrated development environment) while developing something with PHP, JavaScript, Scala, Clojure, C, C++, Groovy, Ruby, Python and many more.

The NetBeans IDE runs virtually anywhere given the fact that a JVM is installed. It is developed in Java. You can download it here: http://netbeans.org/downloads

I recommend Net-beans 7.2

SQL / MySQL SERVER – Count Duplicate Records – Rows


In my previous article SQL SERVER – Delete Duplicate Records – Rows, we have seen how we can delete all the duplicate records in one simple query. In this article we will see how to find count of all the duplicate records in the table. Following query demonstrates usage of GROUP BY, HAVING, ORDER BY in one query and returns the results with duplicate column and its count in descending order.

SELECT YourColumnCOUNT(*) TotalCount
FROM YourTable
GROUP BY YourColumn
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC


Database using simple PHP file without the help of shell access or phpmyadmin


<?php

backup_tables(‘hostname’,’username’,’password’,’db_name’);

/* backup the db OR just a table */

function backup_tables($host,$user,$pass,$name,$tables = ‘*’)

{

$return=”“;

$link = mysql_connect($host,$user,$pass);

if (!$link) {

    die(‘Could not connect: ’ . mysql_error());

}

mysql_select_db($name,$link);

//get all of the tables

if($tables == ‘*’)

{

$tables = array();

$result = mysql_query(‘SHOW TABLES’);

while($row = mysql_fetch_row($result))

{

$tables[] = $row[0];

}

#

}

else

{

$tables = is_array($tables) ? $tables : explode(‘,’,$tables);

}

//cycle through

foreach($tables as $table)

{

$result = mysql_query(‘SELECT * FROM ‘.$table);

$num_fields = mysql_num_fields($result);

//$return.= ‘DROP TABLE ‘.$table.’;’;

$row2 = mysql_fetch_row(mysql_query(‘SHOW CREATE TABLE ‘.$table));

$return.= “nn”.$row2[1].”;nn”;

for ($i = 0; $i < $num_fields; $i++) 

{

while($row = mysql_fetch_row($result))

{

$return.= ‘INSERT INTO ‘.$table.’ VALUES(‘;

for($j=0; $j<$num_fields; $j++) 

{

$row[$j] = addslashes($row[$j]);

$row[$j] = ereg_replace(“n”,”\n”,$row[$j]);

if (isset($row[$j])) { $return.= ‘”’.$row[$j].’”’ ; } else { $return.= ‘”“’; }

if ($j<($num_fields-1)) { $return.= ‘,’; }

}

$return.= “);n”;

}

}

$return.=”nnn”;

}

//save file

$handle = fopen(‘mmmm/db-backup-‘.time().’-‘.(md5(implode(‘,’,$tables))).’.sql’,’w+’);

fwrite($handle,$return);

fclose($handle);

}

?>

PHP Random password generator function


<?php
 
function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength & 2) {
		$vowels .= "AEUY";
	}
	if ($strength & 4) {
		$consonants .= '23456789';
	}
	if ($strength & 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
}

Export to CSV file and download – PHP


function CSVExport() {
$query=”SELECT id,email FROM `newsletterusers` WHERE `status` = 1”;
$sql_csv = mysql_query($query) or die(“Error: ” . mysql_error()); //Replace this line with what is appropriate for your DB abstraction layer

header(“Content-type:text/octect-stream”);
header(“Content-Disposition:attachment;filename=newsletterusers.csv”);
while($row = mysql_fetch_row($sql_csv)) {
print ‘”’ . stripslashes(implode(‘”,”’,$row)) . “"n”;
}
exit;
}

PHP Simple CAPTCHA CODE using SESSION


Create this file :

eg : captcha.php

<?php
session_start();
$ranStr = md5(microtime());
$ranStr = substr($ranStr, 0, 6);
$_SESSION[‘cap_code’] = $ranStr;
$newImage = imagecreatefromjpeg(“cap_bg.jpg”);
$txtColor = imagecolorallocate($newImage, 00, 0);
imagestring($newImage, 555, $ranStr, $txtColor);
header(“Content-type: image/jpeg”);
imagejpeg($newImage);
?>

FORM like this

<form action=”” method=”post”>
<label>Name:</label><br/>
<input type=”text” name=”name” id=”name”/>
<label>Message:</label><br/>
<textarea name=”msg” id=”msg“></textarea>
<label>Enter the contents of image</label>
<input type=”text” name=”captcha” id=”captcha” />
<img src=’captcha.php’ />
<input type=”submit” value=”Submit” id=”submit”/>
</form>

ACTION PAGE : 

<?php
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’)
{
if ($_POST[‘captcha’] == $_SESSION[‘cap_code’]) 
{
// Captcha verification is Correct. Do something here!
}
else 
{
// Captcha verification is wrong. Take other action
}
}
?>

Thank you.

Way2SMS PHP API


Way2SMS PHP code$post_data = “username=username&password=pwd”;
//$header_array[]=”User-Agent:
$url = “http://wwwa.way2sms.com/auth.cl&#8221;;
$cookie = tempnam (“/tmp”, “CURLCOOKIE”);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5” );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch,CURLOPT_REFERER,”http://wwwg.way2sms.com//entry.jsp&#8221;);
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
//$ch = curl_init($url);
//echo $content;
//value of custfrom u have to change according to u’r 
$post_data = “custid=undefined&HiddenAction=instantsms&Action=custfrom450000&login=&pass=&MobNo=9986966496&textArea=test sms”;
$url = “http://wwwa.way2sms.com/FirstServletsms?custid=&#8221;;
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5” );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 ); 
$content = curl_exec( $ch );
$url = “http://wwwa.way2sms.com/jsp/logout.jsp&#8221;;
curl_setopt( $ch, CURLOPT_USERAGENT,”Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5” );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array(“Content-Type: application/x-www-form-urlencoded”,”Accept: */*”));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, “” );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_TIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 0 ); 
$content = curl_exec( $ch );
//echo $content;
?>