PHP class

Class is a core concept of PHP Object Oriented Programming. We can say that class is a template for an object and object is an instance of a class. We use object and instance as the same thing. For  example, Human class, Bycicle class etc.

The General Form of a class

We use class keyword to define a class. So we can define PHP class by following way

class classname{
//Object state
// Object bahavior
}

A PHP class body is  enclosed by curly braces.

PHP class naming convention

Class body surrounded by curly braces {}
Class name starts with capital letter(It is not necessary but we use this convention in our tutorial)
We write all methods and variable within class.

Listing subcategories or chilld categories using php

We can use the following function for getting the subcategories up to any level. It is using recursive technique.

function getSubCats($catid){
        $query= "select cat_id from category where cat_parent_id='$catid'";
        $rst =  $this->db->query($query);
        if($rst->num_rows==0){
            return null;
        }else{
            foreach($rst->rows as $row) {
                $categories[] = $row['cat_id'];
                $children = $this->getSubCats($row['cat_id']);   
                if($children!=null){
                    foreach($children as $child){
                        $categories[] = $child;   
                    }
                }
            }
           
            return $categories;
        }

    }

PHP Encryption and Decryption Function

Sometime we need to convert PHP strings to secret code which cannot be decoded easily by user.  This method will help us to pass coded strings with URL GET arguments and also inside Hidden Form fields ..

Eg : http://myserver.com/index.php?username=j345kjh656bthbf6

PHP has inbuilt base64 encocde and base64 decode functions . but anyone can easily decrypt the string by passing it to base64 decoded functions .. So we need our own encode and decode function so that user cant identify the original content .

Simple encryption and decryption function is given below 

Assign $key with your own secretpasskey

The string encrypted using function encrypt can be decoded only using decrypt function .

For extra security we have included base64 encryption also.

function encrypt($string, $key='mysecretcode123')
{
$result = '';
for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return base64_encode($result);
}

function decrypt($string, $key=' mysecretcode123 ')
{
$result = '';
$string = base64_decode($string);
for($i=0; $i<strlen($string); $i++)
{
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}



Web Services



Web service are applications using open protocols and standards to exchange data between applications or systems.Software applications written in various programming languages(Php, Python, Java etc.) and running on various platforms(Linux, Windows etc.) can use web services to exchange data over computer networks(Internet, Intranet, etc) in a manner similar to inter-process communication on a single computer.

PHP_Wincache - Wincache for PHP 5.4

** Update **: Microsoft's official release of Wincache 1.3 for PHP 5.4 is now available on the Wincache home page: http://www.iis.net/download/wincacheforphp

Here is Wincache version 1.3 BETA, for php 5.4 on IIS with FastCGI.

Note that Wincache also works under the following Apache configuration on Windows:


Download:
  • php_wincache.dll for PHP 5.4 NTS only, there is no thread-safe version.  This build is for PHP NTS x86 built with VC9, the standard PHP release for IIS (there's a link to Microsoft's builds at the bottom of this post, I didn't spot it before writing this, but it makes my build a bit pointless).

Microsoft has not officially released this code yet, so there must still be some problems to iron out.  I tested it for 20 minutes and it seemed to work fine, but I did not test the user cache functions, or make any measurements of time and memory consumption.


Links:

DOH!!

I took my own advice and did some exploring on IIS.net, and found a link to Microsoft's own pre-release builds for Wincache... here is the link: http://sourceforge.net/projects/wincache/files/development/.  I did quite a bit of searching before deciding to build my own, then found this one almost immediately after doing it!

    Contro strucrutes in Php: continue

    continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.
    Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.
    continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.

    <?php
    while (list($key, $value) = each($arr)) {
    if (!($key % 2)) { // skip odd members
    continue;
    }
    do_something_odd($value);
    }

    $i = 0;
    while ($i++ < 5) {
    echo "Outer<br />\n";
    while (1) {
    echo " Middle<br />\n";
    while (1) {
    echo " Inner<br />\n";
    continue 3;
    }
    echo "This never gets output.<br />\n";
    }
    echo "Neither does this.<br />\n";
    }
    ?>


    Omitting the semicolon after continue can lead to confusion. Here's an example of what you shouldn't do.

    <?php
    for ($i = 0; $i < 5; ++$i) {
    if ($i == 2)
    continue
    print "$i\n";
    }
    ?>


    One can expect the result to be :

    0
    1
    3
    4


    but this script will output :

    2


    because the return value of the print() call is int(1), and it will look like the optional numeric argument mentioned above.

    Woltlab Burning Board 2.3.3 Color Palette Fix for Opera

    There is a bug or lack or anything but user can not set color with color palette. Here is fix for this issue If you are using wBB 2.3.x

    1- Open your acp/templates/designpack_colorchooser.htm file with your text editor

    2- Find this block;

    x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
    y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);

    3- Replace with this code;
    e=window.event;      // added
    e.layerX=e.offsetX; // added
    e.layerY=e.offsetY; // added

    x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
    y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);


    4- Do the same things for Cache/templates/acp/designpack_colorchooser.htm file
    -------------------------------------------------------------------------------------

    Woltlab Burning Board 2.3.3 admin panelinde kullanılan Renk paleti Opera ile düzgün çalışması için yapılmış küçük bir güncelleme.

    1- acp/templates/designpack_colorchooser.htm dosyasını Text editörü ile açın

    2- Bu kod satırını bulun;
    x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
    y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);

    3- Bu kod ile değiştirin;
    e=window.event;      // eklendi
    e.layerX=e.offsetX; // eklendi
    e.layerY=e.offsetY; // eklendi

    x = 4 * ((document.all ? event.offsetX : e.layerX)-2);
    y = 4 * ((document.all ? event.offsetY : e.layerY)-2+5);


    4- Aynı şeyi Cache/templates/acp/designpack_colorchooser.htm dosyası içinde yapın. Artık renk paletini Opera tarayıcısı ile birlikte rahatlıkla kullanabilirsiniz.