Everything You Need To Know About PHP - thakurbhaskar

 PHP stands for PHP: Hypertext Preprocessor is a widely used open-source server-side scripting language especially suited for creating dynamic websites and mobile APIs.

PHP supports many databases like MySQL, Solid, PostgreSQL, Oracle, Sybase, generic ODBC, etc. PHP code is embedded within HTML.

It is used to manage dynamic content, session tracking, databases, and also to build an entire e-commerce site.
By default, most of the web hosting servers support PHP and thus it contributes to cost-effectiveness.

Scope of PHP

PHP stands as one of the top languages because of its ability to have a large impact on the outcome with very little code. This amount of efficiency has been the requirement for the past few years in the industry.

On seeing this, companies are investing a good amount of money in hiring proficient PHP developers to fit these shoes and work effectively.

Today, this article will walk you through the most commonly asked PHP interview questions for freshers and experienced in the industry.

What is a session in PHP

A session in PHP is a way to store information to be used across multiple pages of an entire website. The information is not stored on the user’s computer, unlike cookies. In a temporary directory on the server, a file will be created by the session where registered session variables and their values are stored. This information will be available to all pages on the site during that visit.

When you work with an application, you open it, do some modifications, and then you close it. This is much like a Session. The computer knows who you are. It knows when the application is started and ended by you.

But on the internet, the webserver does not know who you are or what you do, because the HTTP address doesn’t maintain a state. This problem is solved using session variables by storing user information to be used across multiple pages (e.g. username, favorite color, etc).

By default, session variables will last until the user closes the browser.

So Session variables hold single user information and are available to all pages in one application.

What are cookies? How to create cookies in PHP?

A cookie is a small record that the server installs on the client’s computer. They store data about a user on the browser. It is used to identify a user and is embedded on the user’s computer when they request a particular page. Each time a similar PC asks for a page with a program, it will send the cookie as well.

After verifying the user’s identity in encrypted form, cookies maintain the session id generated at the back end. It must reside in the browser of the machine. You can store only string values not object because you cannot access any object across the website or web apps.

By default, cookies are URL particular. For example, Gmail cookies are not supported by Yahoo and vice versa. Cookies are temporary and transitory by default. Per site 20 cookies can be created in a single website or web app. 50 bytes is the initial size of the cookie and 4096 bytes is the maximum size of the cookie.

In PHP, we can create cookies using the setcookie() function:

setcookie(name, value, expire, path, domain, secure, httponly);

Here name is mandatory and the remaining parameters are optional.

Example:
setcookie(“instrument_selected”, “guitar”)

Post a Comment

0 Comments