Passing variables between pages

session_start()- is used to start a session $_SESSION[‘variable_name’]- is used to store data in session variable session_destroy()- is used to destroy a session unset($_SESSION[‘variable_name’])- is used to unset a specific variable

pptx35 trang | Chia sẻ: dntpro1256 | Lượt xem: 556 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Passing variables between pages, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
Passing variables between pagesBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.1Summary of the previous lectureOperators in PHPConditional Statements in PHPLooping StatementsArrays in PHPBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.2OutlineSuper Global variablesPassing form dataPassing data with sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.31. Passing form dataForms provide a mean of submitting information from the client to the serverWe can create HTML forms using tagMethod and action are the most common attributes of Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.41. Passing form dataaction - gives the URL of the application that is to receive and process the forms datamethod - sets the HTTP method that the browser uses to send the form's data to the server for processingmost common methods are POST or GETBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.51. Passing form dataGet method : all form data is encoded into the URL, appended the action URL as query string parametersBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.6Action page nameInput field nameValue entered by userAsadasd@gmail.comsubmit1. Passing form dataPost method: form data appears within the message body of the HTTP requestBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.71.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 scopeBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.81.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 dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.9Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.10Asadasd@gmail.comsubmitnameemail$_GETasd@gmail.comAsad1.1 Super Global VariablesBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.11Asadasd@gmail.comsubmitAsadnameemail$_POSTasd@gmail.com1.1 Super Global VariablesBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.12Asadasd@gmail.comsubmitAsadnameemail$_GETasd@gmail.com1.2 Accessing form data on action pageAtion.phpBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.13Asadasd@gmail.comsubmitAsadnameemail$_POSTasd@gmail.com1.2 Accessing form data on action pageAtion.php2. Passing text field dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.14Post MethodText fieldText field name2. Passing text field dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.15Data is receivedDisplay a message2. Passing text field dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.16We are at form pageWe are on action page2. Passing hidden field dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.17Hidden fieldField nameHidden valueAccessing hidden value2. Passing hidden field dataBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.182.3 Getting value from checkboxBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.19labelnamevalueGetting value of ‘C’Getting value of ‘VB’2.3 Getting value from checkboxBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.202.3 Getting value from checkboxBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.21Checking for value of C2.4 Getting value from radio buttonBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.22Same nameValue is setValue is not setGetting value of radio 2.4 Getting value from radio buttonBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.232.5 Getting value from select listBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.24Name of the listOption and value2.5 Getting value from select listBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.253. 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 sessionBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.26Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.27Asadnameemail$_SESSIONasd@gmail.com3. 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 variableBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.283. Passing variables using sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.29Session startsSession variable is createdLink to the next page3. Passing variables using sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.30Session startsSession variable is accessedlink3. Passing variables using sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.31Session variable’s value3. Passing variables using sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.32Session is destroyedSession is accessed3. Passing variables using sessionsBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.33SummarySuper global variablesPassing data with formsUsing session variablesBasharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.34References Chapter 2, “Beginning PHP6,Apache,Mysql web development” by Matt Doyle, Wrox publishers, 2009, ISBN: 0470413964 Chapter 13, “Beginning PHP and MySQL” by W. Jason Gilmore, Apress publisher, 4th edition; 2010, ISBN-13 (electronic): 978-1-4302-3115-8.Basharat Mahmood, Department of Computer Science,CIIT,Islamabad,Pakistan.35

Các file đính kèm theo tài liệu này:

  • pptxlec26_passing_data_between_page_0967_2026974.pptx
Tài liệu liên quan