I don't understand why someone is using the @ in the code, I have seen it with mysql connections but I don't know what it means.. thanks!
$player_name_orig = @$_GET['player'];
if (!$player_name_orig) {
die('You must specify a player name');
}
I don't understand why someone is using the @ in the code, I have seen it with mysql connections but I don't know what it means.. thanks!
$player_name_orig = @$_GET['player'];
if (!$player_name_orig) {
die('You must specify a player name');
}
The @ is the error suppression operator.
In this specific context, it's a (wrong!) way to avoid PHP giving a notice if the player
key does not exist in $_GET
:
If you try this:
unset($_GET['player']); // to make sure
echo $_GET['player'];
You get:
Notice: Undefined index: player in F:\dev\www\index.php on line 35
While if you try this:
unset($_GET['player']); // to make sure
echo @$_GET['player'];
There is no output.
The correct way to do this:
if (empty($_GET['player']) {
die('You must specify a player name');
}