Created
September 24, 2012 13:10
-
-
Save recck/3775881 to your computer and use it in GitHub Desktop.
Week 5 - Day 9 - Using GET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Using GET | |
**/ | |
// the variable $_GET is an array | |
print_r($_GET); | |
// the URL is get.php?page=index | |
echo $_GET['page']; // index | |
// multiple parameters? | |
// get.php?page=profile&user=marcus | |
echo 'Welcome to ' . $_GET['user'] . '\'s profile!'; // Welcome to marcus's profile | |
// creating a link with a random number | |
$number = rand(10,20); // some number between 10 and 20 | |
echo '<a href="get.php?number='.$number.'">Random Number</a>'; | |
// encoding a string to use in the URL | |
$string = 'this is a string with spaces'; | |
echo urlencode($string); // this+is+a+string+with+spaces | |
// using a form! | |
if(!empty($_GET['name'])){ | |
echo 'Your name is ' . htmlentities($_GET['name']) . '<br />'; | |
}else { | |
echo 'Please enter your name!<br />'; | |
} | |
?> | |
<form> | |
Name: <input type="text" name="name" /> | |
<input type="submit" value="What is your name?" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment