The detritus of a Button Monkey

15 Feb

Getting information from a URL

Sometimes you may want to pass something in the URL to extract and use on a following page. For instance you may have a list of items in a table and want to be able to them find out further information Example:

  • Apple
  • Banana
  • Pear

You might want to find information about each item in further page e.g. apple.html, banana.html and pear.html. If you have a long list of items this can then become time consuming. An alternative is to have this data in a database and use a general page to extract the relievant information for the item of interest.

Example:

To extract the information you can then use this:

$item =($_GET[‘item’]);

Or call the function directly from the URL in your SQL statement

SELECT price, origin, company FROM fruit where item ='{$_GET[‘item’]}’

Beware, both methods are trusting that the item value is real. In a real application, this value needs to be checked to prevent SQL injections etc. Also, this method should not be used to pass sensitive info e.g.

http://www.somebigbank.com/customer_info.php?account_number=1234567&PIN_number…..

Leave a Reply

You must be logged in to post a comment.

© 2017 The detritus of a Button Monkey | Entries (RSS) and Comments (RSS)

Design by Your Index - Powered By Wordpress