• My PHP Pages

    This is a complete and free PHP programming course for beginners. Everything you need to get started is set out in section one below.

Sep 24, 2013

Posted by Unknown
3 comments | 12:51 AM
you can send emails using PHP. for send emails  we can use mail() php function. look at below example and change variable values to yours. this script is working with gmail too..

$to      = 'yourmail@mail.com';
$subject = 'Your Subject Goes Here';
$message = '



Your Mail Body Goes Here... !
'; $headers = "From: " . strip_tags($_POST['req-email']) . "\r\n"; $headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n"; $headers .= "CC: php@example.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $message, $headers); echo '
Sent Successfully !..
';

Read More..

Sep 22, 2013

Posted by Unknown
5 comments | 11:32 PM

                                                      You can use PHP ZIP function to make archives using PHP. I have create a PHP Class to zip all folders and files in a given directory you just need to add source directory and  destination path. Look at the code bellow... Copy bellow code and save it as PHP file name it as 'tozip.class.php'





function Zip($source, $destination)
{
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }

    $zip = new ZipArchive();
    if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
        return false;
    }

    $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true)
    {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

        foreach ($files as $file)
        {
            $file = str_replace('\\', '/', $file);

            // Ignore "." and ".." folders
            if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
                continue;

            $file = realpath($file);

            if (is_dir($file) === true)
            {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            }
            else if (is_file($file) === true)
            {
                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
        }
    }
    else if (is_file($source) === true)
    {
        $zip->addFromString(basename($source), file_get_contents($source));
    }

    return $zip->close();
}



Use Bellow Code to execute the function where you need. You need to include 'tozip.class.php' file too


require_once('tozip.class.php');
zip("your_source_path","your_destination_path/your_file_name.zip");


Read More..

Sep 18, 2013

Posted by Unknown
1 comment | 3:05 AM

 For this you basically need two files one is class file and other one is the file that where you calling PDO connection. You can reduce rewriting connection using this OOP PDO script. This class returns after the execution. if connection established successfully it returns '1' else it return error description

 Here is the Class.


dbuser = $dbuser;
 $this->dbpass = $dbpass;
 $this->dbhost = $dbhost;
 $this->dbname = $dbname;
  
       
   }
   function connect()
   {
 try
 {
 $DBH = '';
 $DBH = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname", $this->dbuser, $this->dbpass);
 return 1;
 }
 catch(PDOexception $e)
 {
 return $e->getMessage();
 
 }
 }
}
// how to connect 
//$obj = new db_handler("Username","Password","Host","Database");
//$obj->connect();
?>
Use following code where you need to place connection
connect();
if($db == 1)
{
 echo 'connected';
 }
 else
 {
  echo $db;
  }
?>

Read More..