Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PHP Expert

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.

PHP , Programming

  • Category:- PHP
  • Reference No.:- M92785643
  • Price:- $60

Priced at Now at $60, Verified Solution

Have any Question?


Related Questions in PHP

Final project assignment -requirements specifications -1

FINAL PROJECT ASSIGNMENT - REQUIREMENTS / SPECIFICATIONS - 1. For the final project, you will have to make good use of your CMS using PHP and MySQL for the content delivery. You will have to be able to deliver the conten ...

Question using the course software and week one template as

Question: Using the course software and Week One Template as a starting point, create a new HTML webpage and include the following: • Write the code to display your name in the largest-size heading element. • Write the m ...

Question develop a 5-6 page word document that describes

Question: Develop a 5-6 page Word document that describes the design for a small Web site that meets the following specifications. 1. The Web site includes four or more Web pages designed according to current usability g ...

In php write a simple addtion calculator that reads in two

In PHP write a simple addtion calculator that reads in two values and then add them together and display the output. Be sure to validate both inputs and ensure that it can add 0+0 = Sum: 0. The user should be able to inp ...

Question continue to build on the skills of providing web

Question: Continue to build on the skills of providing Web page content and structure with HTML and Web page style and layout using CSS. Demonstrate the skill of creating a dynamic Web page that includes JavaScript clien ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As