create webpage by php name it as order processing page, add the code necessary t
ID: 3660278 • Letter: C
Question
create webpage by php name it as 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 " " (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.Explanation / Answer
Let's begin by creating the file (lang.php) that will contain the locale-specific information. 1 view plain | print | ? The purpose of this script is to set the preferred language that the user has chosen so that it can be used when the welcome page is loaded. The code starts by checking which language the person selected: 1 if ($_SESSION[lang] == "") { 2 $_SESSION[lang] = "en"; 3 $currLang = "en"; 4 } else { 5 $currLang = $_GET[lang]; 6 $_SESSION[lang] = $currLang; 7 } view plain | print | ? If no locale has been selected, the $currlang variable is set to English, which has an en language code. Otherwise, the $currlang value is set to whatever language the user selected. If your site were Japanese by default, you would change the file to reflect this by using the Japanese locale instead. We will not be using the session_start() function in this script, because the script itself will be included in the welcome page and it will be valid for any scripts included after it has been declared. PHP Script to Render the Appropriate Locale The next section of this script contains a switch() function, which will match the selected language code to a character set and a language code and then send the headers. 1 switch($currLang) { 2 case "en": 3 define("CHARSET","ISO-8859-1"); 4 define("LANGCODE", "en"); 5 break; 6 case "de": 7 define("CHARSET","ISO-8859-1"); 8 define("LANGCODE", "de"); 9 break; 10 case "ja": 11 define("CHARSET","UTF-8"); 12 define("LANGCODE", "ja"); 13 break; 14 default: 15 define("CHARSET","ISO-8859-1"); 16 define("LANGCODE", "en"); 17 break; 18 } 19 header("Content-Type: text/html;charset=".CHARSET); 20 header("Content-Language: ".LANGCODE); view plain | print | ? When the appropriate character set and language code has been set, it is then assigned to the CHARSET and LANGCODE constant variables, which will be used by the main page. These constants are used in the display script to create the proper META tags regarding character set and language code. Although the headers are sent in this script, it's a good idea to ensure that they are part of the page itself to aid in any necessary input from forms. That's all there is to this script. The Welcome Message Text Next, we need to set the welcome message that will be displayed on the welcome page. Here's the script (txt.php) that will do just that: 1 view plain | print | ? The language depends on what is contained in the $_SESSION['lang'] session variable. We use the switch() function to evaluate and check what language has been selected. The defineString() function will match whatever language the user chooses to the appropriate text. As an example, this is the code used when the user chooses English as the preferred language: 1 case "en": 2 define("WELCOME_TXT","Welcome!"); 3 define("CHOOSE_TXT","Choose Language"); 4 break; view plain | print | ? Note that the default language is English, as shown in the switch() statement: 1 default: 2 define("WELCOME_TXT","Welcome!"); 3 define("CHOOSE_TXT","Choose Language"); 4 break; view plain | print | ? The WELCOME_TXT constant variable contains the text that welcomes a user to the site, which can be in any of the available languages. The CHOOSE_TXT constant variable contains the text that introduces the language selection process.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.