Skip to content

Instantly share code, notes, and snippets.

@recck
Created September 24, 2012 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recck/3775881 to your computer and use it in GitHub Desktop.
Save recck/3775881 to your computer and use it in GitHub Desktop.
Week 5 - Day 9 - Using GET
<?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