google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: October 2015

Friday, October 23, 2015

php notes

Special data type in php
 Null is a special data type which can have only one value: NULL.
A variable of data type NULL is a variable that has no value assigned to it.
Ex:-
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
Output:- NULL



Abstract class in php:-
1. PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method's signature - they cannot define the implementation.
2. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility.
3. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same.
4. For example, if the child class defines an optional argument, where the abstract method's signature does not, there is no conflict in the signature. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ.
Abstract example:-
<?php
abstract class AbstractClass
{
    // Our abstract method only needs to define the required arguments
    abstract protected function prefixName($name);

}

class ConcreteClass extends AbstractClass
{

    // Our child class may define optional arguments not in the parent's signature
    public function prefixName($name, $separator = ".") {
        if ($name == "Pacman") {
            $prefix = "Mr";
        } elseif ($name == "Pacwoman") {
            $prefix = "Mrs";
        } else {
            $prefix = "";
        }
        return "{$prefix}{$separator} {$name}";
    }
}

$class = new ConcreteClass;
echo $class->prefixName("Pacman"), "\n";
echo $class->prefixName("Pacwoman"), "\n";
?>
The above example will output:
Mr. Pacman
Mrs. Pacwoman


COOKIE IN PHP:
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Purpose of cookie:-
Cookies make the interaction between users and web sites faster and easier. Without cookies, it would be very difficult for a web site to allow a visitor to fill up a shopping cart or to remember the user's preferences or registration details for a future visit.

Web sites use cookies mainly because they save time and make the browsing experience more efficient and enjoyable. Web sites often use cookies for the purposes of collecting demographic information about their users.

Cookies enable web sites to monitor their users' web surfing habits and profile them for marketing purposes (for example, to find out which products or services they are interested in and send them targeted advertisements).
 In php :-
1. PHP transparently supports HTTP cookies.
2. Cookies are a mechanism for storing data in the remote browser and thus tracking or identifying return users.
3. We can set cookies using the setcookie() or setrawcookie() function.
4. Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser. This is the same limitation that header() has
5. We can use the output buffering functions to delay the script output until you have decided whether or not to set any cookies or send any headers.
6. Any cookies sent to you from the client will automatically be included into a $_COOKIE auto-global array if variables_order contains "C". To assign multiple values to a single cookie, just add [ ] to the cookie name.
7. Depending on register_globals, regular PHP variables can be created from cookies. However it's not recommended to rely on them as this feature is often turned off for the sake of security
Setting new cookie:-
<?php
setcookie("name","value",time()+$int);
/*name is your cookie's name
value is cookie's value
$int is time of cookie expires*/
?>
Getting Cookie:-
<?php
echo $_COOKIE["your cookie name"];
?>
Updating Cookie:-
<?php
setcookie("color","red");
echo $_COOKIE["color"];
/*color is red*/
/* your codes and functions*/
setcookie("color","blue");
echo $_COOKIE["color"];
/*new color is blue*/
?>
Deleting Cookie:-
<?php
unset($_COOKIE["yourcookie"]);
/*Or*/
setcookie("yourcookie","yourvalue",time()-1);
/*it expired so it's deleted*/
?>.


रघुपति राघव राजाराम पतित पावन सीताराम ॥

 रघुपति राघव राजाराम पतित पावन सीताराम ॥ सुंदर विग्रह मेघश्याम गंगा तुलसी शालग्राम ॥ भद्रगिरीश्वर सीताराम भगत-जनप्रिय सीताराम ॥  जानकीरमणा स...