Web Technologies and Programming Lecture 24
Passing Form Data
action
method (POST or GET)
When to Use GET?
When to Use POST?
Compare GET vs. POST
Super Global Variables
Passing data with forms
Passing Text Field Data
Passing Hidden Field Data
Getting Value From Checkbox
Getting Value From Radio Button
Getting Value From Select List
Using session Variables
54 trang |
Chia sẻ: hoant3298 | Lượt xem: 614 | Lượt tải: 0
Bạn đang xem trước 20 trang tài liệu Web Technologies and Programming Lecture 24, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
1Web Technologies and ProgrammingLecture 242Passing Data Between Pages 3Summary of Previous LectureOperators in PHPArithmetic Operators: +, - ,*, /, %, **Assignment Operators: =String Operators: . , .=Increment/decrement Operators: ++ , --Logical Operators: AND, OR, NOT, XOR, &&, ||, !Comparison Operators: >, =Equality Operators: ==, !=, === Conditional statementsif statement - executes some code if one condition is trueif...else statement - executes some code if a condition is true and another code if that condition is falseif...elseif....else statement - executes different codes for more than two conditionsswitch statement - selects one of many blocks of code to be executed4Summary of Previous LectureLooping statementsFor LoopWhile LoopDo-While LoopForEach LoopArrays in PHP Associative arraysSorting arrays5Today’s Lecture OutlineSuper Global variablesPassing form dataPassing data with sessions61. Passing Form DataForms provide a mean of submitting information from the client to the server.We can create HTML forms using tagMethod and action are the most common attributes of 71. Passing Form Dataactiongives the URL of the application that is to receive and process the forms datamethodsets the HTTP method that the browser uses to send the form's data to the server for processingmost common methods are POST or GET81. Passing Form DataWhen to Use GET?You can use GET (the default method):If the form submission is passive (like a search engine query), and without sensitive information.91. Passing Form DataWhen to Use GET?When you use GET, the form data will be visible in the page address:action_page.php?firstname=Mickey&lastname=Mouse101. Passing Form DataGet Method:all Form Data is encoded into the URL, appended the action URL as query string parametersInformation is visible to everyoneIt has the amount limitGet method should only be used when the data is not sensitiveGet should not be used when sending passwords or sensitive data111. Passing Form Data12URL where Information is to be submittedGet Method1. Passing Form Data13Getting NameGetting Email1. Passing Form Data14Information to be SentURL contains all Data that was sent from previous page1. Passing Form DataWhen to Use POST?You should use POST:If the form is updating data, or includes sensitive information (password).POST offers better security because the submitted data is not visible in the page address.151. Passing form dataPost method:Form Data appears within the message body of the HTTP requestInformation sent will be invisible to othersNo limit on data amountWhen using sensitive data such as passwords, use Post Method.161. Passing Form Data17URL where Information is to be submittedGet Method1. Passing Form Data18Getting Posted NameGetting Posted Email1. Passing Form Data19Information to be SentURL contains no Data that was sent from previous page1. Compare GET vs. POST201.1 Super Global VariablesSeveral predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope - and you can access them from any function, class or file without having to do anything special.211.1 Super Global VariablesPHP automatically makes few variables available in your programThese are array variables and can be accessed by nameThese variables are called super-global variables because they can be accessed without regard to scope221.1 Super Global Variables$_GET:contains all the query string variables that were attached to the URL$_POST:contains all the submitted form variables and their data231.1 Super Global Variables$_GET:Test $GET 241.1 Super Global Variables$_POST:"> Name: 2526nameemail$_GETtehseen.abbasi@comsats.edu.pkTehseen1.1 Super Global Variables27Tehseennameemail$_POSTtehseen.abbasi@comsats.edu.pk1.1 Super Global Variables28Tehseennameemail$_GETtehseen.abbasi@comsats.edu.pk1.2 Accessing Form Data on Action Page29Tehseennameemail$_POSTtehseen.abbasi@comsats.edu.pk1.2 Accessing Form Data on Action Page2. Passing Text Field Data30Post MethodText FieldText Field Name2. Passing Text Field Data31Data ReceivedDisplay A Message2. Passing Text Field Data32Form PageAction Page2. Passing Hidden Field Data33Hidden FieldField NameHidden Value2. Passing Hidden Field Data34Accessing Hidden Value2. Passing Hidden Field Data35No Third EntryHidden Field Data2.3 Getting Value From Checkbox36CheckBoxNameValue2.3 Getting Value From Checkbox37PHP ValueASP Value2.3 Getting Value From Checkbox382.3 Getting Value From Checkbox39Checking for Value of PHP2.4 Getting Value From Radio Button40Same NameValue SetValue Not SetGetting Value from Radio Button2.4 Getting Value From Radio Button412.5 Getting Value From Select List42Name of ListOption and ValueGetting Value of List2.5 Getting Value From Select List433. Passing Variables Using SessionsA session is basically a temporary set of variables that exists only until the browser has shut down$_SESSION:represents data available to a PHP script that has previously been stored in a session4445Tehseennameemail$_SESSIONTehseen.abbasi@comsats.edu.pk3. Passing Variables Using SessionsFirst Page2nd Pagenth page..3. Passing Variables Using Sessionssession_start()is used to start a session$_SESSION[‘variable_name’]is used to store data in session variablesession_destroy()is used to destroy a sessionunset($_SESSION[‘variable_name’])is used to unset a specific variable463. Passing Variables Using Sessions47Session StartsSession Variable CreatedLink to Next Page3. Passing Variables Using Sessions48Session StartsSession Variable CreatedLink Page3. Passing variables using sessions49Session Variable’s Value3. Passing variables using sessions50Destroying SessionAccessing Session3. Passing variables using sessions51Session AccessedSession DestroyedSummary of Today’s LecturePassing Form Dataactionmethod (POST or GET)When to Use GET?When to Use POST?Compare GET vs. POSTSuper Global Variables52Summary of Today’s LecturePassing data with formsPassing Text Field DataPassing Hidden Field DataGetting Value From CheckboxGetting Value From Radio ButtonGetting Value From Select ListUsing session Variables 53THANK YOU54
Các file đính kèm theo tài liệu này:
- lecture_24_wt_passing_data_between_pages_3502_2028586.pptx