[TOC]
โ At the end of this lesson you should be able to:
-
Use GET and POST HTTP methods
-
Use HTTP cookies and sessions
-
Develop web application that uses HTML, CSS, and PHP programming language
- Tโeam
- โฐ Pomodoro technique: 20 minutes focus work - 5 minutes break (checking number of likes and shares in SocMed are not included) - Repeat (this will increase productivity)
- Another productivity tip: Play video in 1.25 - 1.5x speed
- ๐ฅ Hydrate.
Use this repo for the following activities: https://github.com/PSU-CC6-REPOs/legendary-garbanzo
In the following activities the webpages are predesigned, your team will write a PHP code to complete the requirements of every website.
โ :warning: You don't have to edit the index.php
After watching the Get and Post write PHP code for this problem. In folder named web2 you can find the index.php and fav.php files. The objective of this activity is for you to get and display the values from forms. The requirements for this activity are the following:
-
When the user click the "Submit This Form" button
-
Test if the user input his / her name
- if yes test if the color of the wine and dish are not null, if both of them are not null display "You really enjoy - especially with a nice wine"
- if no display appropriate message
-
In folder named web3 you can find the index.php and calc.php files. The objective of this activity is for you to learn how to manipulate the submitted values.
โ :warning: You don't have to edit the index.php, provide the missing code according the in-line comment provided in the calc.php file
- When the user click the "Calculate" button
- Test if the inputted values are numbers. Use the PHP is_numeric() function to ensure that two numbers have indeed been entered.
- If yes test if an arithmetical operation has been selected, a switch statement determines the type of operation and performs the result.
- If no a request to retry will be prompted
- Test if the inputted values are numbers. Use the PHP is_numeric() function to ensure that two numbers have indeed been entered.
You can use cookies to prevent direct access to pages of a website without logging in first to that website. The log-in process creates the cookie, then PHP scripts on all other pages confirm the existence of that cookie before displaying their content.
In folder named web4 you can find index.php, loggedin.php and anotherpage.php files. The objective of this activity is for you to learn the following:
- create HTTP cookie
- test if the cookie exist
In this activity the log-in page creates a cookie called "auth" with a value of "ok" when the user submits the form with both "username" and "password" input fields completed. The browser is redireced to a second page (loggedin.php) that seeks the cookie. If that page does not find the cookie, the browser is redirected to the log-in page. Another page (anotherpage.php) in this example makes the same check, and has the same response.
HTTP is a "stateless" protocol, hence each web page request is unique and treat as independent transaction.
A session is a way to store information (in variables) to be used across multiple pages. Unlike a cookie, the information is not stored on the users computer. - w3schools.com
How does it work? How does it know it's me?
Most sessions set a user-key on the user's computer that looks something like this: 765487cf34ert8dede5a562e4f3a7e12. Then, when a session is opened on another page, it scans the computer for a user-key. If there is a match, it accesses that session, if not, it starts a new session.
Session variables stored user information and it will be available until you close the browser.
After watching the Sessions Tutorials answer the following:
โWhat function do we use to start a session?
โWhere are these session variables stored?
In folder named web5 you can find index.php file. The objective of this activity is for you to learn how to manage and use session variables.
Write a php code in index.php that display the number of visits in this page. As the user reload the page the count of visit is increasing. If the count of visits reach 5 display a message "Thank you for visiting the page a lot." and when the count reaches 10 the browser is redirected to a second page (congratulations.php).
Check the video sample-output in the folder for your reference.
During this pandemic, we usually encounter logbooks in malls, stores, schools, almost every where. Under Republic Act 11469, Bayanihan to Heal as One Act requires us to provide truthful information. The logApp is a sample application that logs the individual's personal information and the date and time he/she visits the place. To protect an individual's personal information (RA 10173, Data Privacy Act of 2012), only users with an admin account can view the list of individuals who visited the premises.
Clone the logApp boilerplate: https://github.com/PSU-CC6-REPOs/logApp-scaling-octo
Your task is to:
- prepare database for logApp
- provide database name
- create tables: person, account
- identify fields for two tables
- write a PHP code for the following requirements:
- login
- If user credentials does not exist in user account prompt appropriate message
- display the list of logs
- register or log the individual's personal information
- login
- HTML
- footer.php - replace the link, direct it to your github account
โ