Explore the techniques of file storage and session variables

Assignment Help PHP Web Programming
Reference no: EM131947985

Advanced Server-Side Scripting

As you gain experience with server-side scripting, you discover increasingly sophisticated ways to improve the user experience. In this Application, you explore the techniques of file storage and session variables.

To prepare for this Application:

Saving to a File

An online order system is not very useful if it cannot remember the orders it accepts. Operating systems allow programs to read and write files so that they may store information. Websites frequently rely on more sophisticated database management systems, but that is beyond the scope of this course. The fundamental operations you use on a file are:

- Open: Find or create the file and make it available to the program

- Read: Get content from the file

- Write: Add or modify content in a file

- Close: Disconnect the file from the program

In your order processing page, add the code necessary to save to a file the date, name, age, and item for every order. Which use indicator allows the program to add new data to the end of the file? Does each order appear on a separate line in your file? Write the escape code "\n" (backslash followed immediately by the letter "n") at the end of the file output. This code tells PHP to end the line there. The next record will start on a new line.

How can you tell where one value ends and the next value begins in the file? You could try separating the fields with a comma or some other specific character. What problems do you see with this method? How can you address them? Include your completed PHP source code and a screenshot of the file contents.

Using Session Variables

Websites often rely on client cookies to remember information (called "state") about a user. The Web browser can store cookies for a specific or an indefinite period. Developers also use server-side session keys to retain state for a limited time.

You now use session variables to remember a user's name and age. The idea is to save a customer from having to provide the same information several times in a session. Add PHP code to your "catalog" order-processing page to:

- Call the session_start function.

- Detect whether or not the name session variable has a value (use the array_key_exists function); if not, use the name and age post values to set the name and age session variables.

- Use the session variables, not the post variables, in the confirmation message and when writing to the file.
The effect of these changes is to remember the user's name and age after the user has a successful submission. Verify that this page still works properly. Next, modify your "catalog" page to:

- Call the session_start function.

- Detect whether or not the name session variable has a value; if so, display name and age as text; if not, display the name and age input fields.

These changes take advantage of the saved information. Describe the additional changes you would have to make to "forget" a user's name and age.

Reference no: EM131947985

Questions Cloud

Price of option for one point move in underlying asset : Which one of the following choices measures the change in price of an option for a one point move in the underlying asset?
Training and development in the workplace : What impact does affirmative action have on training and development in the workplace?
How will you incorporate ethical practices into your market : How will you incorporate ethical practices into your marketing and selling?Write the management and personnel plan ?
What do you think about the rules for s-corporations : Read the following article from the Motley Fool. The article is entitled S-Corporations, Beware!, and answer the following questions:
Explore the techniques of file storage and session variables : An online order system is not very useful if it cannot remember the orders it accepts. Operating systems allow programs to read and write files
How each model addresses the brain changes : Select two models of addiction in the Lewis text. Compare how each model addresses the brain changes (neurological effects) associated with using a substance.
Would banking reform threaten the us free-market economy : 1. Would banking reform threaten the U.S. free-market economy? 2. Do we really need reform in the banking industry?
New value of the company after capital restructuring : What will be the new value of the company after the capital restructuring?
What role does communication play in effectively managing : 1. What role does communication play in effectively managing diversity?

Reviews

Write a Review

PHP Web Programming Questions & Answers

  Random integral numbers based on normal distribution

Prepare a system to generate random integral numbers based on normal distribution. Study Data Generator's structure and extend number generation type to activate normal distribution.

  Shopping cart program for web applications class

Shopping Cart program for web applications class. Allows user to browse while keeping track of the items in which they will purchase at the end on the order page link and this will give a final price for all items.

  Create a web site for an apple farm

Create a web site for an apple farm. Create an HTML5 form allowing visitors to create an account with the site. Account details are to be stored in your MySQL database. Information should be stored in a secure way.

  Develop a dynamic website open university

Develop a dynamic website Open University

  Sample website project

This website consists of three sections: a narrative, a storyboard, and a business Website.

  Online banking application

Designing and developing a web applications The company you are working has secured a contract with a local banking group to develop an ONLINE BANKING APPLICATION using PHP and MySQL.

  Design a dynamic database

Design a dynamic database using Mangodb, html , and php.

  Show the accessibility and usability of website

The webpage must have several menus about country Azerbaijan such as "About Azerbaijan" "History" "Geography" "Landscape" and "Accessibility" menu.

  Implement a web application

Implement a web application called CS320Starter, which is similar to the crowd funding platform Kickstarter where people raise funds for their projects.

  Prepare an ajax enabled web form

Prepare an AJAX enabled web form utilising a ListView control that will allow logged-in staff to list, edit, delete, insert magazine details for magazines from a selected magazine category.

  Create a very simple order system as a web application

Create a very simple Order System as a web application.

  Which of the following jsp expressions is valid

A JSP expression can contain any Java expression that evaluates to a String object, Java object, primitive type, primitive type or Java object

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd