PHP Interview Question Set 7

Categories: PHP

What is the method to register a variable into a session?




 What is $_SESSION in PHP?

A session creates a file in a temporary directory on the server where registered session variables and their session id are stored. This data will be available to all pages on the site amid that visit.

The area of the temporary record is controlled by a setting in the php.ini document called session.save_path.

What is PHP session_start() and session_destroy() function?

PHP session_start() function is used to start the session. It starts new or resumes the current session. It returns the current session if the session is created already. If the session is not available, it creates and returns new sessions.

What is the difference between session and cookie?

The main difference between session and cookie is that cookies are stored on user's computer in the text file format while sessions are stored on the server side.

Cookies can't hold multiple variables, on the other hand, Session can hold multiple variables.

You can manually set an expiry for a cookie, while session only remains active as long as browser is open.

 Write syntax to open a file in PHP?

PHP fopen() function is used to open file or URL and returns resource. It accepts two arguments: $filename and $mode.


resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context

How to read a file in PHP?

PHP provides various functions to read data from the file. Different functions allow you to read all file data, read data line by line, and read data character by character.

PHP file read functions are given below:

  1. fread()
  2. fgets()
  3. fgetc()

How to write in a file in PHP?

PHP fwrite() and fputs() functions are used to write data into file. To write data into a file, you need to use w, r+, w+, x, x+, c or c+ mode.

How to delete file in PHP?

The unlink() function is used to delete a file in PHP.

bool unlink (string $filename)      

 What is the method to execute a PHP script from the command line?

You should just run the PHP command line interface (CLI) and specify the file name of the script to be executed as follows.

How to upload file in PHP?

The move_uploaded_file() function is used to upload file in PHP.

bool move_uploaded_file ( string $filename , string $destination )    

How to download file in PHP?

The readfile() function is used to download the file in PHP.

int readfile ( string $filename )     

Top Blogs
PHP freshers Interview Questions PHP Interview Questions and Answers for Freshers & Experienced Published at:- PHP Tutorial From beginner Published at:- PHP Interview Question Set 1 Published at:- PHP Interview Question Set 3 Published at:- PHP Interview Question Set 4 Published at:- PHP Interview Question Set 6 Published at:- PHP Interview Question Set 7 Published at:- PHP Interview Question Set 8 Published at:- PHP Interview Question Set 9 Published at:- Top 5 PHP Structures Published at:- 8 Motivations To pick Php web Advancement for IT Business Published at:- Team
The content on R4R is created by expert teams.