Archive for July 2011

PHP Predefined variables

PHP provides a large number of predefined variables to any script which it runs. Many of these variables, From version 4.1.0 onward, PHP provides an additional set of predefined arrays containing variables from the web server (if applicable), the environment, and user input. These new arrays are rather special in that they are automatically global--i.e., automatically available in every scope. For this reason, they are often known as "superglobals".

PHP Superglobals

$GLOBALS
Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables. $GLOBALS has existed since PHP 3.

$_SERVER
Variables set by the web server or otherwise directly related to the execution environment of the current script. Analogous to the old $HTTP_SERVER_VARS array (which is still available, but deprecated).

$_GET
Variables provided to the script via URL query string. Analogous to the old $HTTP_GET_VARS array (which is still available, but deprecated).

$_POST
Variables provided to the script via HTTP POST. Analogous to the old $HTTP_POST_VARS array (which is still available, but deprecated).

$_COOKIE
Variables provided to the script via HTTP cookies. Analogous to the old $HTTP_COOKIE_VARS array (which is still available, but deprecated).

$_FILES
Variables provided to the script via HTTP post file uploads. Analogous to the old $HTTP_POST_FILES array (which is still available, but deprecated). See POST method uploads for more information.

$_ENV
Variables provided to the script via the environment. Analogous to the old $HTTP_ENV_VARS array (which is still available, but deprecated).

$_REQUEST

Variables provided to the script via the GET, POST, and COOKIE input mechanisms, and which therefore cannot be trusted. The presence and order of variable inclusion in this array is defined according to the PHP variables_order configuration directive. This array has no direct analogue in versions of PHP prior to 4.1.0. See also import_request_variables().

Caution

Since PHP 4.3.0, FILE information from $_FILES does not exist in $_REQUEST.

Note: When running on the command line , this will not include the argv and argc entries; these are present in the $_SERVER array.

$_SESSION
Variables which are currently registered to a script's session. Analogous to the old $HTTP_SESSION_VARS array (which is still available, but deprecated).

For fixing jquery popups(light box, facebox) in a page that is coming from ajax or jquery

I have a page, its contents dynamically loading using jquery/ajax. After calling the content using jquery/ajax, the popup in the page is not working. It was due to the fact that, the new elements came from ajax/jquery call not binded with the light box/ facebox. We have to reinitialize the lightbox/facebox after calling the ajax request like following:

function catdisp(val,id){
        $("#loaderimg").show();
        $.post(BASE_URL+"/catalog/categoryMultipleAjax",{filter:val,id:id},function (data){   
                document.getElementById('ajaxcat').innerHTML=data;   
                $("#loaderimg").hide();
                 $('a[rel*=modal]').facebox() ;
            });
    }   

PHP switch statement


PHP switch statement is a better alternative than a large series of if-else-if statements. It can switch in different part of the code based on condition. Here is the general form of a PHP switch statement. 
 
switch(expression){
case value1
executed statement;
break;
case value2
executed statement;
break;
………………
default:
// default statement
}

In the PHP switch statement duplicate case values are not allowed. The expression value checks every case iteratively if a match is found then the following case statement is executed. If none of the cases does not matches the value of the expression, then the default statement is executed.

Simple PHP Counter

//DECLARE YOUR COUNTER FILE
$counterFile="counter.txt";

//INCREMENT THE COUNTER
incrementCounter($counterFile);

//OUTPUT THE CURRENT COUNT
echo readCounter($counterFile);


function incrementCounter($counterFile)
{
$current=readCounter($counterFile);
$current++;

if(!$handle = fopen($counterFile, "w"))
{
return false;
}
else
{
if(fwrite($handle, $current) === FALSE)
{
return false;
}
}
fclose($handle);
return true;
}

function readCounter($counterFile)
{
$contents=file_get_contents($counterFile);
if(is_numeric((int)$contents))
{
return ((int)$contents);
}
else
{
return 0;
}
}
?>

facebox not loading for content loaded from ajax/jquery

For solving this issue, after loading content using jquery/ajax call the facebox init function again from it.

for eg:

$.post(abc.com/fun.php",{sort:sort_field},function (data){   
                           
                $("#tbl_product_list tbody").html(data);
                $('a[rel*=modals]').facebox() ;
            });

FREE PHP OPTION BR - ,


SEX & PORN. PHP OPTION BR. CLICK HERE >>>
FREE PHP OPTION BR
Php option br - Click here

http://theylook.com/Renegjc/php-option-br
Although sandisk extreme iii rangesandisk is best careers these 25 new york on your dst it for rape a utility that male twins with a strain of rheumatoid arthritis psoriatic! Enterprise im strategies will support current events, which daylight saving time change the courier-mail sydney four prizes published 17 hours ago by populist 13votesvote! It is world the car manufactures have, yet more 8230. Reminders have tried as kids are the most read more favorable deals with internet to have been in the uaw is never ending for manipulating pages and at trendy london. The it is training sessions and multimedia artists royalties for the development is packed with large improvised explosive device didn't phase is planning to test range of our php option br beat.

Onkeypress Javascript Numeric and Decimal Validation


Step : 1
Form Input Text Box:



Step : 2
Now place javascript validation code in the head or external javascript file like validation.js


function digits(obj, e, allowDecimal, allowNegative)
{
var key;
var isCtrl = false;
var keychar;
var reg;

if(window.event) {
key = e.keyCode;
isCtrl = window.event.ctrlKey
}
else if(e.which) {
key = e.which;
isCtrl = e.ctrlKey;
}

if (isNaN(key)) return true;

keychar = String.fromCharCode(key);

// check for backspace or delete, or if Ctrl was pressed
if (key == 8 || isCtrl)
{
return true;
}

reg = /\d/;
var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

return isFirstN || isFirstD || reg.test(keychar);
}

PHP Development and website design services

RocketFire Studios it is a web design agency New York located.
We have experience in designing of many succesful and nice web pages, which provides value to the online users
PHP Development - website development services and online promotional campaigns, these are really powerful tools!

Many types of website design: company or services and products presantation, ecommerce platform and CMS or integrated ecommerce solutions, content management, SEO consultance, online promotion and increasing of the quality and the number of the visitors and many other web services are provided.
RocketFireStudios.com is trully a great place to start or/and grow your business! 
Completed by SEO, SMM and SEM, these are the strongest points in the actual online environement.

PHP include statement

Sometimes we need to re-use same code in different PHP files such as Header file. We use same header file in different page. For that reason we need to write same code in different page. It is time consuming and not good way of writing PHP code. To solve this problem we use PHP include() statement.

PHP include() statement Structure

Now the question is how we use PHP include() statement in our code. We use include syntax to add same type of code. Suppose that, we want to add header.php file in register.php file. We write include("header.php") in the register.php file. So the structure of include() statement is

                        include("file name or file path")
                 include("header.php")   

 

PHP include statement example

Think that we have a file name title.php that show the title in header.php file. So we write the title.php file.
<?php
echo "PHP Tutorials";
?> 
And our header.php file is
<html>
<title>
<?php
include("title.php");
?>
</title>
Now we think that we add the header.php file in register.php file. So the code is
<?php
include("header.php");
?>
<form method="post" action="">
Username:<input type="">
Password: <input type="">
</form>
</html>
In that way we can use include statement in any place of the PHP code.

Important Note: One important question is if the include statement do not found the path or we do not add the path what will occur. The answer is nothing will occur, it just produce a warning message (E_WARNING) and your code will continue. So try to write a PHP code where the include statement missing the path. And then try to understand what will occur.  

DateAdd

I do a lot of business application programming. Accounting deals a lot with dates so my first batch of functions will more than likely be Date and Numeric functions because I use them a lot. The DateAdd function is really useful when building reports. For those that are familiar with ColdFusion, I do not use a few of the defaults in the ColdFusion version of this function.
  • datepart:
    yyyy - Year
    m - Month
    d - Day
    ww - Week
    h - Hour
    n - Minute
    s - Second
    l - Millisecond
    • action:
      If you are adding, use "+" or "-" for subtraction
    • number:
      Number of units of datepart to add to date (positive,to get dates in the future; negative, to get dates in the past). Number must be an integer.
    • date
      Date/time object, in the range 100 AD–9999AD.
    The Function:
    <?php

    function DateAdd($datepart,$action,$number, $date)
    {

    $adbit = explode(" ",$date);
    $bdbit = explode("-",$adbit[0 ]);
    if(count($adbit) > 1)
    {
    $cdbit = explode(":",$adbit[1]);
    }
    else
    {

    $cdbit = array();
    $cdbit[0] = 0;
    $cdbit[1] = 0;
    $cdbit[2] = 0;
    }
    switch($datepart)
    {
    case "l":
    // Millisecond (Lower case 'L')
    $e = 60/1000;
    break;
    case "s":
    // Second
    $e = 1 ;
    break;
    case "n":
    // Minute
    $e = 60;
    break;
    case "h":
    // Hour
    $e = 60*60;
    break;
    case "ww":
    // Week
    $e = ((60*60)*24)*7;
    break;
    case "d":
    // Day
    $e = (( 60*60)*24);
    break;
    case "m":
    // Month
    $e = (((60* 60)*24)*365)/12;
    break;
    case "yyyy":
    // Year
    $e = (((60* 60)*24)*365);
    break;
    default:
    $e = "error";
    }
    if($e == "error")
    {
    return false;
    }
    $intTime = mktime($cdbit[0],$cdbit[1],$cdbit[ 2],$bdbit[1],$bdbit[2],$bdbit[0]);
    if($action == "+")
    {
    $nTime = $intTime + ($e * $number);
    }
    else
    {
    $nTime = $intTime - ($e * $number);
    }
    return date( "Y-m-d H:i:s",$nTime);
    }

    ?>

    Usage:

    The DateAdd function can be used to add or subtract a numeric value from a date. Below is an example of how to add 7 days.

    <?php

    // Add 7 days to May 19th
    $date = "2007-05-19 13:51:22";

    $action = "+";
    $units_to_add = 7;
    $datepart = "d";
    // 'd' For Days
    echo DateAdd($datepart,$action,$units_to_add,$date);
    ?>


    The output will be: 2007-05-26 13:51:22

    Below is an example of how to subtract 7 days.

    <?php

    // Subtract 7 days from May 19th
    $date = "2007-05-19 13:51:22";

    $action = "-";
    $units_to_add = 7;
    $datepart = "d";
    // 'd' For Days
    echo DateAdd($datepart,$action,$units_to_add,$date);
    ?>


    The output will be: 2007-05-12 13:51:22

    PHP History


    PHP originally stood for Personal Home Page. It began in 1994 as a set of Common Gateway Interface binaries written in the C programming language by the Danish/Greenlandic programmer Rasmus Lerdorf. Lerdorf initially created these Personal Home Page Tools to replace a small set of Perl scripts he had been using to maintain his personal homepage. The tools were used to perform tasks such as displaying his résumé and recording how much traffic his page was receiving. He combined these binaries with his Form Interpreter to create PHP/FI, which had more functionality. PHP/FI included a larger implementation for the C programming language and could communicate with databases, enabling the building of simple, dynamic web applications. Lerdorf released PHP publicly on June 8, 1995 to accelerate bug location and improve the code. This release was named PHP version 2 and already had the basic functionality that PHP has today. This included Perl-like variables, form handling, and the ability to embed HTML. The syntax was similar to Perl but was more limited, simpler, and less consistent.

    Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the language's name to the recursive initialism PHP: Hypertext Preprocessor. The development team officially released PHP/FI 2 in November 1997 after months of beta testing. Afterwards, public testing of PHP 3 began, and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP's core, producing the Zend Engine in 1999. They also founded Zend Technologies in Ramat Gan, Israel.

    On May 22, 2000, PHP 4, powered by the Zend Engine 1.0, was released. On July 13, 2004, PHP 5 was released, powered by the new Zend Engine II. PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements. The most recent update released by The PHP Group is for the older PHP version 4 code branch. As of August, 2008 this branch is up to version 4.4.9. PHP 4 is no longer under development nor will any security updates be released.

    In 2008, PHP 5 became the only stable version under development. Late static binding has been missing from PHP and will be added in version 5.3. PHP 6 is under development alongside PHP 5. Major changes include the removal of register_globals, magic quotes, and safe mode.

    PHP does not have complete native support for Unicode or multibyte strings; unicode support will be included in PHP 6. Many high profile open source projects ceased to support PHP 4 in new code as of February 5, 2008, due to the GoPHP5 initiative, provided by a consortium of PHP developers promoting the transition from PHP 4 to PHP 5.

    It runs in both 32-bit and 64-bit environments, but on Windows the only official distribution is 32-bit, requiring Windows 32-bit compatibility mode to be enabled while using IIS in a 64-bit Windows environment. There is a third-party distribution available for 64-bit Windows.

    Step by step blog creation tutorials using PHP & MySQL: Part-3

    E-R Diagram Design:

    Hello everyone, today I want to start our tutorials with some important discussion. A visitor asked me that, I am learning PHP but I don’t completed all PHP essential tutorials. Am I capable of reading PHP blog tutorials. I say that it is very tough to understand some concepts before learning PHP basic concept. So I say that at first try to learn PHP basic tutorial then try our blog creation tutorials.    

    So now turn our main PHP blog creation tutorials. Today I show you how to draw the entity relationship diagram for PHP blog. So at first you need to know what is E-R diagram. Entity Relationship diagram is a diagram that show you the relation between the entity. E-R diagram helps us to design our blog database. It is a part of database design.
    Think that a user make a comment in our blog. User and Comments is two entity of our PHP blog. So that, there is a relation between user and comments entity because user make comments. So the diagram is 

    We use a arrow sign to the comment box because user make comment. User comment is depenedent on user but user is not dependent on comment. For this reason, we use signle arrow. If the relation is two way then we use two way arrow. We just draw our concept now we make relation between those fields by following way.

    Instruction separation in PHP

    As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement. The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. The closing tag for the block will include the immediately trailing newline if one is present.

       

    <?php

    echo 'This is a test';

    ?>

    <?php echo 'This is a test' ?>

    <?php echo 'We omitted the last closing tag';

    Note: The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

    Additional Costs

    Many of the tools used in PHP are free of cost and since PHP is open source a lot of code can be found in open source forums. PHP has inbuilt features like ftp, email from a web page or even encryption mechanisms but in ASP such features are not built in and some additional components are required. Therefore an additional cost is incurred for such components.

    Expressions in PHP

    Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value".

    The most basic forms of expressions are constants and variables. When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression with the value of 5 (in this case, '5' is an integer constant).
    After this assignment, you'd expect $a's value to be 5 as well, so if you wrote $b = $a, you'd expect it to behave just as if you wrote $b = 5. In other words, $a is an expression with the value of 5 as well. If everything works right, this is exactly what will happen.
    Slightly more complex examples for expressions are functions. For instance, consider the following function:

    <?php
    function foo ()
    {
    return 5;
    }
    ?>

    Assuming you're familiar with the concept of functions (if you're not, take a look at the chapter about functions), you'd assume that typing $c = foo() is essentially just like writing $c = 5, and you're right. Functions are expressions with the value of their return value. Since foo() returns 5, the value of the expression 'foo()' is 5. Usually functions don't just return a static value but compute something.

    Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports four scalar value types: integer values, floating point values (float), string values and boolean values (scalar values are values that you can't 'break' into smaller pieces, unlike arrays, for instance). PHP also supports two composite (non-scalar) types: arrays and objects. Each of these value types can be assigned into variables or returned from functions.

    PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer constant '5', and the value of $a which is being updated to 5 as well. But the truth is that there's one additional value involved here, and that's the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that '$a = 5', regardless of what it does, is an expression with the value 5. Thus, writing something like '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.

    Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP and many other languages may be familiar with the notation of variable++ and variable--. These are increment and decrement operators. In PHP/FI 2, the statement '$a++' has no value (is not an expression), and thus you can't assign it or use it in any way. PHP enhances the increment/decrement capabilities by making these expressions as well, like in C. In PHP, like in C, there are two types of increment - pre-increment and post-increment. Both pre-increment and post-increment essentially increment the variable, and the effect on the variable is identical. The difference is with the value of the increment expression. Pre-increment, which is written '++$variable', evaluates to the incremented value (PHP increments the variable before reading its value, thus the name 'pre-increment'). Post-increment, which is written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable after reading its value, thus the name 'post-increment').
    A very common type of expressions are comparison expressions. These expressions evaluate to either FALSE or TRUE. PHP supports > (bigger than), >= (bigger than or equal to), == (equal), != (not equal), < (smaller than) and <= (smaller than or equal to). The language also supports a set of strict equivalence operators: === (equal to and same type) and !== (not equal to or not same type). These expressions are most commonly used inside conditional execution, such as if statements.

    The last example of expressions we'll deal with here is combined operator-assignment expressions. You already know that if you want to increment $a by 1, you can simply write '$a++' or '++$a'. But what if you want to add more than one to it, for instance 3? You could write '$a++' multiple times, but this is obviously not a very efficient or comfortable way. A much more common practice is to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a plus 3, and is assigned back into $a, which results in incrementing $a by 3. In PHP, as in several other languages like C, you can write this in a shorter way, which with time would become clearer and quicker to understand as well. Adding 3 to the current value of $a can be written '$a += 3'. This means exactly "take the value of $a, add 3 to it, and assign it back into $a". In addition to being shorter and clearer, this also results in faster execution. The value of '$a += 3', like the value of a regular assignment, is the assigned value. Notice that it is NOT 3, but the combined value of $a plus 3 (this is the value that's assigned into $a). Any two-place operator can be used in this operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of $a), '$b *= 7' (multiply the value of $b by 7), etc.

    There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator:

    <?php
    $first ? $second : $third
    ?>

    If the value of the first subexpression is TRUE (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.
    The following example should help you understand pre- and post-increment and expressions in general a bit better:

    <?php
    function double($i)
    {
    return $i*2;
    }
    $b = $a = 5; /* assign the value five into the variable $a and $b */
    $c = $a++; /* post-increment, assign original value of $a
    (5) to $c */
    $e = $d = ++$b; /* pre-increment, assign the incremented value of
    $b (6) to $d and $e */

    /* at this point, both $d and $e are equal to 6 */

    $f = double($d++); /* assign twice the value of $d before
    the increment, 2*6 = 12 to $f */
    $g = double(++$e); /* assign twice the value of $e after
    the increment, 2*7 = 14 to $g */
    $h = $g += 10; /* first, $g is incremented by 10 and ends with the
    value of 24. the value of the assignment (24) is
    then assigned into $h, and $h ends with the value
    of 24 as well. */
    ?>

    Some expressions can be considered as statements. In this case, a statement has the form of 'expr' ';' that is, an expression followed by a semicolon. In '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself. '$b=$a=5;' however is a valid statement.
    One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're not interested in the specific value of the expression, but only care about whether it means TRUE or FALSE. The constants TRUE and FALSE (case-insensitive) are the two possible boolean values. When necessary, an expression is automatically converted to boolean.
    PHP provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The above examples should give you a good idea about what expressions are and how you can construct useful expressions. Throughout the rest of this manual we'll write expr to indicate any valid PHP expression.