Showing posts with label Difference between. Show all posts
Showing posts with label Difference between. Show all posts

Sunday 8 June 2014

PHP Sessions and Cookie and Security

PHP Session
Session is Super global variable, that preserve certain data across multiple requests. A visitor accessing your web-site is assigned a unique id, the so-called session id. Its either stored in a cookie on the user side OR is propagated in the URL.

Why its is used
1. Get the Number of unique visitor
2. For Login functionality we need this.
3. It tell us whether user is registered OR not.

Requirements 
No external libraries are needed to build this extension.

Installation 
Session is enabled in PHP by default. If you would not like to build your PHP with session support, you should specify the
--disable-session

Session configuration options
NameDefaultChangeableChangelog
session.save_path""PHP_INI_ALL
session.name"PHPSESSID"PHP_INI_ALL
session.save_handler"files"PHP_INI_ALL
session.auto_start"0"PHP_INI_PERDIR
session.gc_probability"1"PHP_INI_ALL
session.gc_divisor"100"PHP_INI_ALLAvailable since PHP 4.3.2.
session.gc_maxlifetime"1440"PHP_INI_ALL
session.serialize_handler"php"PHP_INI_ALL
session.cookie_lifetime"0"PHP_INI_ALL
session.cookie_path"/"PHP_INI_ALL
session.cookie_domain""PHP_INI_ALL
session.cookie_secure""PHP_INI_ALLAvailable since PHP 4.0.4.
session.cookie_httponly""PHP_INI_ALLAvailable since PHP 5.2.0.
session.use_strict_mode"0"PHP_INI_ALLAvailable since PHP 5.5.2.
session.use_cookies"1"PHP_INI_ALL
session.use_only_cookies"1"PHP_INI_ALLAvailable since PHP 4.3.0.
session.referer_check""PHP_INI_ALL
session.entropy_file""PHP_INI_ALL
session.entropy_length"0"PHP_INI_ALL
session.cache_limiter"nocache"PHP_INI_ALL
session.cache_expire"180"PHP_INI_ALL
session.use_trans_sid"0"PHP_INI_ALLPHP_INI_ALL in PHP <= 4.2.3. PHP_INI_PERDIR in PHP < 5. Available since PHP 4.0.3.
session.bug_compat_42"1"PHP_INI_ALLAvailable since PHP 4.3.0. Removed in PHP 5.4.0.
session.bug_compat_warn"1"PHP_INI_ALLAvailable since PHP 4.3.0. Removed in PHP 5.4.0.
session.hash_function"0"PHP_INI_ALLAvailable since PHP 5.0.0.
session.hash_bits_per_character"4"PHP_INI_ALLAvailable since PHP 5.0.0.
url_rewriter.tags"a=href,area=href,frame=src,form=,fieldset="PHP_INI_ALLAvailable since PHP 4.0.4.
session.upload_progress.enabled"1"PHP_INI_PERDIRAvailable since PHP 5.4.0.
session.upload_progress.cleanup"1"PHP_INI_PERDIRAvailable since PHP 5.4.0.
session.upload_progress.prefix"upload_progress_"PHP_INI_PERDIRAvailable since PHP 5.4.0.
session.upload_progress.name"PHP_SESSION_UPLOAD_PROGRESS"PHP_INI_PERDIRAvailable since PHP 5.4.0.
session.upload_progress.freq"1%"PHP_INI_PERDIRAvailable since PHP 5.4.0.
session.upload_progress.min_freq"1"PHP_INI_PERDIRAvailable since PHP 5.4.0.


How to set the Cookie?
bool setcookie ($name, $value);//set the cookie
bool setcookie ($name, $value,time()+3600); //set the cookie with expire 1 hour
bool setcookie ($name, $value, $expire = 0, $path, $domain, $secure = false, $httponly = false );//all parameter of set cookie
bool setrawcookie ($name, $value, $expire = 0, $path, $domain, $secure = false, $httponly = false );//Send a cookie without urlencoding the cookie value
Parameter of set_cookie function
name: The name of the cookie.
value: The value of the cookie. This value is stored on the clients computer; do not store sensitive information.
expire: The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoc. If set to 0, or omitted, the cookie will expire when the browser closes.
path: The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain.
domain: The domain that the cookie is available to.
secure: Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. 
httponly: When TRUE the cookie will be made accessible only through the HTTP protocol. 

How to get cookie?
echo $_COOKIE["cookieName"];

How to print all cookie?
print_r($_COOKIE);

How to delete a cookie?
setcookie ("cookieName", "", time() - 60);

How to set Array Cookie?
setcookie("cookieName[one]", "c_1");
setcookie("cookieName[three]", "c_2");
setcookie("cookieName[two]", "c_3");

How to get Array cookie?
print_r($_COOKIE["cookieName"]);

Tuesday 20 May 2014

Difference between WebService and API

Difference between WebService and API


S.No
Web Service
API
1
Interaction between two machines over a network. Interaction between two API.
2
Uses SOAP, REST, and XML-RPC as a means of communication. It may use any way to communication
3
Web Services involves calling of system. We can render form in one line, one by one element, element OR  decorator OR error separately.
4
Web service might not contain a complete set of specifications and sometimes might not be able to perform all the tasks that may be possible from a complete API. An API consists of a complete set of rules and specifications for a software program to follow in order to facilitate interaction.
5
All Web services are APIs All APIs are not Web services
6
A Web service always needs a network for its operation API doesn't need a network for its operation
7
WebServices are services available over internet. You can call these services and get so information in your application without know how it works. For example weather webservices gives you information about the city weather. API is a collection of class which provide you some functionality like Google api gives google-search.



Wednesday 26 March 2014

Difference Between MyISAM and innoDB - MySQL

Difference Between MyISAM and innoDB - MySQL

MySQL is Open Source database means its free to use and reliable. that's why lot of application use mysql as a database. But when we going to create  a new database, lot of doubts comes in mind like what will be database maxsize, Database engine and number of tables in database.

Before you create you databases, you must think below important points.
  • Why I am creating database.
  • What are most use of database means going to add/update statement or search the list
  • What type of record will be stored means in english character or chinse/japense character
  • Maximum records in table.
  • What are different types of database engine supported by MySQL.
  • What tables will use for tractions


Following are list of different database engines types


Name Vendor License Transactional active development
Archive Oracle GPL No Yes
Aria Monty Program GPL No Yes
Berkeley DB Oracle No
BlitzDB GPL No Yes
CONNECT Monty Program GPL Yes
CSV Oracle GPL No Yes
Falcon Oracle GPL Yes No
InnoDB Oracle GPL Yes Yes
MyISAM Oracle GPL No No
NDB Oracle Yes Yes
InfiniDB Calpont GPL Yes Yes
TokuDB TokuTek Modified GPL Yes Yes
XtraDB Percona GPL Yes Yes
Federated Oracle GPL No
FederatedX Monty Program GPL Yes
CassandraSE Monty Program GPL No Yes
sequence Monty Program GPL Yes Yes
mroonga Monty Program GPL Yes
SphinxSE Sphinx Technologies GPL No Yes




Following are Difference between MyISam and InnoDB
MyISAM Advantage
1. Faster than InnoDB for search results
2. support Full-text indexing
3. When use "select" statement, gives faster results as compare to Innodb

InnoDB Advantage

1. Support for transactions (ACID: Atomicity, Consistency, Isolation, Durability).
2. Better "Row-level locking"
3. Foreign key constraints
4. Repair better incase of table corruption
5. Support Rollback abilities
6. Automatic crash recovery

MyISAM Disadvantage

1. Cascading delete/update not support
2. NOt support ACID compliance
3. Row limit 4,284,867,296
4. When we use indexing, insert/update/delete become bit slow
5. Not Support Row Locking


InnoDB Disadvantage

1. Not support full text indexing (<5.6 mysql version)
2. Can't compressed
3. Search Slow as compare to MyISAM

Change table engine to MyISAM
ALTER TABLE `tableName` ENGINE = MYISAM

Change table engine to innodb
ALTER TABLE `tableName` ENGINE = innodb

Tuesday 18 March 2014

Difference Between Zend framework 2 VS Zend framework 1

Zend framework is framework created by zend company who is owner of PHP. It means it is more reliable as compare to other framework and CMS. That's why most of people are using Zend for their project. 


It is lots of qualities and are below:

  1. Its created by zend.com - Owner of PHP.
  2. Most of the third party API like GData, PDF, AUth, ACL etc are available.
  3. They provide support .
  4. Time by time, Up-dation are available so that you get always best in the industry.
  5. Excellent tutorial is available not for current version but also for previous version.

Now, Zend have provided Version2 because they always provide better to the php developer. Zend2 has its own qualities. Now we have more reason to select zend in our project.


Before start working zend2 we should compare with zend1 and get to know pros/cons of zend2.


So, Here are few compare of Zend framework 2 VS Zend framework 1.


Architecture:
ZF1 is based on MVC (Model View Controller)
ZF2 is based on MOVE (Model Operations Views Events)

Conventions:
Class name in ZF1 was Zend_Db_Table for class in Zend/Db/Table.php 
Class name in ZF2 is Zend\Db\Adapter for class in Zend/Db/Table.php 

Community:
ZF1 was backed by Zend Technologies (and few other, unnamed).
ZF2 was backed by Zend Technologies, Google and Microsoft.

Size of installation:
30Mb for ZF1
2.5 for ZF2 (zipped)

Performance:
PHP: ZF2 is 4 times slower than ZF1
Because ZF2 call more functions in background as compare to ZF1.
SQL: ZF2 is little  Faster than ZF1 

Compare Performance

  1. http://www.developerknowhow.com/zf1-vs-zf2/
  2. http://www.enrise.com/2012/02/zend-framework-2-performance/

For More detail, Please visit zend.com

Tuesday 2 July 2013

Difference between JSON and JSONP

Difference between JSON and JSONP

Full Form of JSON
JavaScript Object Notation

Full Form of JSONP
JavaScript Object Notation with Padding.



Json is stardard format that is human readable used to transmit information from one server to another server.
Jsonp is a json with ability to transmit information to another domain.



JSONP is JSON with padding, that is, you put a string at the beginning and a pair of parenthesis around it. 

JSON Example
{"Name": "Foo", "Id": 1234, "Rank": 7};

JSONP Example - In this you can call a function
functionCall({"Name": "Foo", "Id": 1234, "Rank": 7});




With JSON you can't send request to another domain whereas JSONP is really a simply trick to overcome XMLHttpRequest same domain policy. In JSONP you can send request to a different domain.) 
Demo with JSONP
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
        <script>
            $(document).ready(function(){
                $.ajax({
                    url: 'http://twitter.com/status/user_timeline/padraicb.json?count=5',
                    dataType: 'jsonp',
                    success: function(dataWeGotViaJsonp){
                        var htmlData = '';
                        var len = dataWeGotViaJsonp.length;
                        for(var i=0;i<len;i++){
                            twitterEntry = dataWeGotViaJsonp[i];
                            htmlData += '<p>
<img src = "' + twitterEntry.user.profile_image_url_https +'"/>' + twitterEntry['text'] + '</p>
'
                        }
                        $('#MyTwitterFeed').html(htmlData);
                    }
                });
            })
        </script>
        <div id="MyTwitterFeed">
</div>



Wednesday 12 June 2013

Difference Between Cakephp and Zend Framework

S.No Cakephp Zend Framewok
1
It is just framework. It is Both framework and library.
2
In View Form helper, there is form elements, validation available. In View Form helper, there is form elements, validation, filters(like strip_tags), order of elements, sub form, and decoraters are available.
3
we can render form elements one by one We can render form in one line, one by one element, element OR  decorator OR error separetly.
4
Form configuration can not done by through configuation file Zend_form can be do configuration through zend_cofig or xml
5
When cake start, It load all library that's why Its not good for small project. Its library is too big as compare to cakephp. If you are  not using any component then it will not load by default.
6
It uses front controller design and singleton design pattern. It use front controller pattern, factory patter, strategy pattern, singleton pattern.
7
It is good for fast development. It is best, if you application are using webservices
8
ACL, Auth like comonents are easily availbele for cakephp. It has its own ACL, Auth components and upto deeper level.
9
When cake start, It load all library that's why Its not good for small project. Its library is too big as compare to cakephp. If you are  not using any component then it will not load by default.
10
It have session component It have Zend Session and Zend Registery components.
11
Its class name does not map with file location Its mapping,
If any class name is Zend_forms_abc
file location is Zend/Forms/abc.php
12
Mostly used for fast development. Mostly used for web services

Tuesday 28 May 2013

Difference between Abstract class and Interface in PHP

Difference between Abstract class and Interface in PHP

S.No
Abstract Class
Interface
1
For abstract class, a method must be declared as abstract. In class, at-least one method must be declared as abstract.


Variable can not be declared
For Interface, class must be declared as Interface.

In interface, all methods by default all are abstract methods.


Variable can not be declared
2
The Abstract methods can declare with Access modifiers like public, private, protected.

When implementing in subclass these methods must be defined with the same visibility (Like public, protected).
All methods are public in interface.
3
Abstract class can contain variables, concrete methods and constants.Interfaces cannot contain variables and concrete methods except constants.
4
A class can Inherit only one Abstract class
and
Multiple inheritance is not possible for Abstract class.
A class can implement many interfaces
and
Multiple interface inheritance is possible.


   



Similarity between abstract and interface classes

1) We can not create object of abstract and interfaces.

2) Abstract method must be there in abstract and interface

3) We have to defined all the methods which are abstract in base class.



Example of Interface
//Interface
interface car {

    public function audio();

    public function video();
}

//how to implements interface
class mycar implements car {

    public $owner = 'Arun';

    public function audio(){
        return 'Audio functionality.';
    }

    public function video(){
        return 'Video functionality.';
    }

    public function owner() {
        return $this->owner;
    }

}

$mycarObj = new mycar();
echo $mycarObj->audio(); //Audio functionality
echo $mycarObj->video(); //video functionality
echo $mycarObj->owner(); //Arun



Example of Abstract
//Abstract class
abstract class car {
    //Abstract method
    abstract public function audio();

    public function video() {
        return 'video functionality.';
    }

}

class mycar extends car {
    public $owner='Arun';
    public function audio() {
        return 'Audio functionality.';
    }
    public function owner() {
        return $this->owner;
    }    

}

$mycarObj = new mycar();
echo $mycarObj->audio(); //Audio functionality
echo $mycarObj->video(); //video functionality
echo $mycarObj->owner(); //Arun