10 Sessions Cookies And Error Handling

Web Technology II · Unit 10

Sessions, Cookies, and Error Handling

Exam-focused notes for Sessions, Cookies, and Error Handling (Web Technology II, BIT301): what the TU syllabus asks and how it has actually been tested, with 13 solved past questions from this unit.

What this unit covers

  • Session creation and initialization
  • Session management and termination
  • User data maintenance with sessions
  • Cookie creation and handling
  • Cookie and session comparison
  • Error handling and error handlers
  • Error reporting and configuration
  • Error suppression techniques
  • Exception handling and try catch
  • Error logs and logging
  • HTTP authentication methods
  • PHP.ini configuration settings

Cookie creation and handling

20825 marks

How can you handle cookies and sessions? Illustrate with examples. [5]

Note: The reference notes did not contain material on this topic. The following answer is based on standard PHP web development curriculum as taught in BSc CSIT. --- A cookie is a small piece of data stored on the client's browser by the server. It is used ...

Full solved answer →
20805 marks

What is a cookie? Write PHP program to create cookie. [5]

A cookie is a small piece of data that a server sends to the user's web browser. The browser stores it and sends it back with subsequent requests to the same server. Cookies are commonly used to: - Remember user login information - Track user sessions - Sto...

Full solved answer →

HTTP authentication methods

20825 marks

What is HTTP authentication? How is it done? [5]

HTTP Authentication is a built-in mechanism provided by the HTTP protocol that allows a web server to challenge a client (browser) for credentials (username and password) before granting access to a protected resource. It is defined in the HTTP specificatio...

Full solved answer →

Error handling and error handlers

20825 marks

What is the error handler? Write a program to demonstrate error handler function. [5]

An error handler is a user-defined function that is called automatically whenever a PHP error occurs. Instead of displaying the default PHP error messages, a custom error handler allows the programmer to control how errors are handled, such as logging them,...

Full solved answer →
20815 marks

Define error handlers and error logs with examples. [5]

A running PHP script reports trouble in two different ways, and the two words in this question name the two halves of the response to it. An error handler decides what happens at the moment something goes wrong, while an error log is the permanent written r...

Full solved answer →
20795 marks

What is error handler? Write a PHP program to show use of error handler to format and print errors. [5]

An error handler is a function of your own that PHP calls whenever it raises a diagnostic, in place of printing its built in message. Instead of a raw grey line of text in the middle of a page, the handler receives the details as arguments and can format th...

Full solved answer →
05 marks

Define error handling, error reporting and error suppression. [5]

These three terms describe three different responses to the same event, a PHP script running into something it cannot do. Error handling is what the program does about it, error reporting is how much PHP announces about it, and error suppression is the deli...

Full solved answer →

Session creation and initialization

20815 marks

What is a session? How can you handle sessions in PHP? [5]

A session is a way to store information (in variables) to be used across multiple pages of a website. Unlike cookies, session data is stored on the server side. Each user gets a unique session ID which is used to identify and retrieve their session data. No...

Full solved answer →
20795 marks

Write a PHP program for illustrating the starting and ending of session. [5]

HTTP has no memory, so two requests from the same visitor look unrelated to the server. A session gives them a thread: PHP generates a session id, sends it to the browser in a cookie, and keeps a matching store on the server. The $SESSION array is that stor...

Full solved answer →

Error reporting and configuration

20815 marks

Describe the concepts of display_errors, variables_order and request_order in PHP.ini Settings. [5]

These three directives in php.ini control what a PHP script says when something goes wrong and which request data the engine hands it in the first place. The first is an error visibility setting; the other two decide which superglobals get filled and in wha...

Full solved answer →
20805 marks

Define error reporting and error suppression with examples. [5]

These two settings sit on opposite sides of the same question: how much should a PHP script say when something goes wrong. Error reporting decides which classes of problem PHP announces at all, and error suppression silences the announcement for one express...

Full solved answer →

Exception handling and try catch

20805 marks

Write a PHP program to illustrate the use of exception handling. [5]

Exception handling lets a script deal with a runtime failure at the place that knows what to do about it, instead of letting the failure end the request. The code that might fail goes inside try, throw raises an object describing the failure, one or more ca...

Full solved answer →

User data maintenance with sessions

05 marks

What is session? Write a PHP program for maintaining user data with sessions. [5]

HTTP is stateless: each request stands alone and the server has no memory of the one before it. A session supplies that memory. When a session starts, PHP generates a long random session id, sends it to the browser in a cookie, and keeps a matching store on...

Full solved answer →