February 13th 2007
(1) PHP Lesson 7
Educational, Programming, Tutorials
My lessons are now into their second week and we’ve still got a way to go yet. This week we will be looking into IF and WHILE statements, $_GET, $_POST and we’ll also look into arrays near the end of the week.
In the previous lesson we went into detail about IF and WHILE statements and in Friday’s big round up I introduced you to $_POST and $_GET. Today we’re going to look further at $_GET and what it’s used for.
Lesson 7: $_GET and URLs
When we have a URL that includes the values of certain variables, we can use this to get the values. Say we had a URL like this:
http://www.eop.org.uk/index.php?name=sunny%20man&cool=yes
We use $_GET to grab the values of the name and cool variables. Obviously this isn’t a secure way to transport variables around your site - we’ll look at a more secure way later on into the tutorials - this is the most simple way.
<?php
$name = $_GET['name']; //$name = “sunny man”
$cool = $_GET[’cool’]; //$cool = “yes”
?>
Tomorrow I’ll be talking about $_POST and how it can be confusing when to use the name and id attributes on form field inputs.
/images/9r_leaf.png)
[…] Yesterday we did a simple lesson on $_GET and how to get values from a URL. Today another simple lesson on $_POST and the confusion that comes with it. I introduced you to $_POST in last Friday’s big special and today we are going into much more detail. […]