Question:- Differentiate between require and include?
Answer:- Require and include both are used to include a file, but if data is not found include sends warning whereas require sends Fatal error.
Question:- Explain setcookie() function in PHP?
Answer:- PHP setcookie() function is used to set cookie with HTTP response. Once the cookie is set, you can access it by $_COOKIE superglobal variable.
Question:- What is Syntax of setcookie() function in PHP?
Answer:- bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )
Question:- How can you retrieve a cookie value?
Answer:- echo $_COOKIE ["user"];
Question:- What is a session?
Answer:- PHP Engine creates a logical object to preserve data across subsequent HTTP requests, which is known as session. Sessions generally store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same user. Simply, it maintains data of an user (browser).
Question:- What is $_SESSION in PHP?
Answer:- 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. At the point when a session is begun following things happen -
Question:- When a session is begun what following things are happen?
Answer:- 1. PHP first makes two duplicates of one of a kind session id for that particular session of the client which is an arbitrary string of 32 hexadecimal numbers, for example, 3c7foj34c3jjhkyepop2fc937e3443. 2. One copy of unique session id automatically sent to the user?s computer for the sake of synchronization in future ahead, and one copy is being maintained at server side till the session is running. 3. Whenever you want to access the page of website or web app, then session id of the current user will be associated with the HTTP header, and that will be compared by the session id which is being maintained at the server. After completing the comparison process, you can easily access the page of the website or web app 4. A session ends when the user closes the browser, or after leaving the site, the server will terminate the session after a predetermined period, commonly 30 minutes duration.
Question:- What is PHP session_start() and session_destroy() function?
Answer:- 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.
Question:- What is PHP session_start() and session_destroy() function?
Answer:- 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.
Question:- What is the difference between session and cookie?
Answer:- The main difference between session and cookie is that cookies are stored on users computer in the text file format while sessions are stored on the server side. Cookies cant 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.
Question:- Write syntax to open a file in PHP?
Answer:- PHP fopen() function is used to open file or URL and returns resource. It accepts two arguments: $filename and $mode Syntax: resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
Question:- How to read a file in PHP?
Answer:- 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: fread(), fgets(), fgetc()
Question:- How to write in a file in PHP?
Answer:- 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.
