I’m trying to learn PHP, and I figured I’d make myself a simple exercise of making a site that if someone goes to it, they get “Hello friend!” but if my wife (who is named Dawn) goes to it, she gets a different message.
Unfortunately, it’s always showing up as blank and I’m not really sure why.
I know it works for index.html with just text, and I know it works for index.php as long as I have no <?php tag in it (just text works). But when I try to make it actual php, it just fails.
- I’d like
site/index.phpto yield
“Hello friend!” - I’d like
site/index.php?who=Bobto
yield “Hello friend!” - I’d like
site/index.php?who=Dawnto
yield “Hello Dawn! I love you!”
Here’s what I have:
<?php
print 'Hello ';
$who = $_GET("who");
if($who && $who == "Dawn")
print "Dawn! I love you!";
else
print "friend!";
/>
So, what’s wrong?
Access to arrays (
$_GETis an array), like in Java, uses square brackets:Also
if($who)evaluates to true if$whois non-false, to check it’s set you need to useisset:Last, as noted by @Shivan, the end tag should be
?>, not/>.