Web Systems Development (CSC-215) Lecture 11: Query Strings Wednesday 14th March 2018
Saving State Most of the scripts we have done up to now have had significance for single instances After the scripts are run, removed from web server's memory
Saving State Data needs to be saved in between browser request, when, for example, You need to keep track of items in a shopping cart To keep track of a user posting comments in forums Not just logged in users, state for returning users ...
Need to preserve state of user interaction
Saving State Query strings Cookies HTTP authentication Sessions
Query Strings Quick convenient way to pass small amounts of data between browser requests Example: keywords entered in a search function Only use in situations where sending incorrect data won't compromise security
Building Query Strings A query string is simply a string of characters stored in a URL Manually create a URL containing a query string in PHP script, then include the URL as a link within the displayed page or in an email, for example PHP even provides some built - in functions to make the process easier
Query strings only allow specific characters, so use urlencode() to include exceptions
Accessing Data
Accessing Data
example
Pagination Uses query strings to create previous and next page links
Lecture content adapted from chapter 13 of Learning PHP, MySQL, JavaScript, CSS & HTML5 & chapter 10 of Beginning PHP 5.3