Latest Posts

Showing posts with label Sql Interview Question. Show all posts
Showing posts with label Sql Interview Question. Show all posts

Thursday, February 23, 2017

How sessions work in PHP

Recently I was helping one of my client in hiring PHP developer . I was surprise to know that 80 % of candidate don't know about how PHP session works.

People were aware about the functions like session_start , $_SESSION etc but not  aware about how it works over the HTTP. Most of the candidate stuck when they were told that HTTP is connection less protocol and on every request a new connection is created . 

https://www.tutorialspoint.com/php/php_sessions.htm

In PHP Session management is a way to make data accessible across the various pages.

A session creates a file in a temporary directory on the server where registered session variables and their values are stored. This data will be available to all pages on the site during that visit.
The location of the temporary file is determined by a setting in the php.ini file called session.save_path. Before using any session variable make sure you have setup this path.
When a session is started following things happen −
  • PHP first creates a unique identifier for that particular session which is a random string of 32 hexadecimal numbers such as 3c7foj34c3jj973hjkop2fc937e3443.
  • A cookie called PHPSESSID is automatically sent to the user's computer to store unique session identification string.
  • A file is automatically created on the server in the designated temporary directory and bears the name of the unique identifier prefixed by sess_ ie sess_3c7foj34c3jj973hjkop2fc937e3443.
When a PHP script wants to retrieve the value from a session variable, PHP automatically gets the unique session identifier string from the PHPSESSID cookie and then looks in its temporary directory for the file bearing that name and a validation can be done by comparing both values.
A session ends when the user loses the browser or after leaving the site, the server will terminate the session after a predetermined period of time, commonly 30 minutes duration.

Starting a PHP Session

A PHP session is easily started by making a call to the session_start() function.This function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.


Changing the name of PHPSESSID 

We can change the name by calling session_name before any call to session_start or session_register .

session_name('mySessionName');
session_start();

 Other method is to set the name in php.ini . The variable session.name specifies the name of the session which is used as cookie name. It should only contain alphanumeric characters. Defaults to PHPSESSID

For further reference please visit to below link

http://se.php.net/manual/en/session.configuration.php#ini.session.name
 

Tuesday, July 7, 2015

Indexes on sql Server table


I have discussed with many interviewer and interviewee about the SQL Server tricky interview Questions. Most of them told me that Indexes and Triggers are most important area. Today we will discuss more about the Indexes and Triggers. To make it simple i will post question first and then explain the answer.

1. What is clustered and Non Clustered Index?

The leaf nodes of a clustered index contain the data pages i.e. in simple terms the clustered index stores the information how physically information is stored.It is same as the index page of a book.

A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. 
In simple terms we can say that the non clustered Index stores the logical ordering of data.
  
2. How many Cluster Index you can create on a table?

One Clustered Index is allowed per table

3. Can we create Clustered Index on Null value column? 
Yes we can create Clustered Index on a non-unique and nullable column. If the clustered index is not a unique index, SQL Server makes any duplicate keys unique by adding an internally generated value called a unique identifier.

4. How many Null value can a clustered Index column can take?


Only one NULL value is allowed in Clustered Index column as it is considered as a unique value.

5. Can we create Clustered Index on Non primary key column? 

 yes. We can create Clustered Index on Non primary key.

6. How many NON-Clustered Index you can create on a table?

SQL Server allows maximum up to 249 NON-CLUSTERED indexes that can be created in single table. This has been increased to 999 in SQL Server 2008 R2 version for both 32-bit and 64-bit server.

7. Can we drop Cluster Index on Primary Key. If yes then how it will work ?

Yes We can drop a Clustered Index on Primary key column and create it on another column.

8. Can we create a table without Clustered Index.

Yes we can.The table is called as Heap.Data is stored in the heap without specifying an order. To find a row we must now RID.  

9. Can we create Non-Clustered index on a table which donst have Clustered Index.

Yes we can create Non clustered index on a table which don't have clustered index