Reputation:
So I've seen other posts that show how to do this, but only with "clean" URLs like example.com/this/this
, what I want to do I get the username from this URL example.com/profile.php?username=joe
So that I'd end up getting say Joe as a result. Any ideas?
Upvotes: 0
Views: 64
Reputation: 797
When you see a url string line the following
profile.php?user=foo&name=bar
You can access the parameters after the ?
. They will be stored in the $_GET
array
. The ampersand is the separator of variable name and value pairs. In this case: user=foo
, the variable name is on the left side, of the seperator '=', user
accessed by $_GET['user']
and the value of an echo
would be foo
.
Upvotes: 0
Reputation: 18598
You have to write like
if(isset($_GET['username']) && $_GET['username']!="")
{
echo $_GET['username'];
}
Upvotes: 0
Reputation: 946
Just echo your $_GET value like so:
echo $_GET['username'];
It will return:
joe
Upvotes: 1