Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the '@' character near the '$' character [duplicate]

Tags:

php

I have this piece of code which I need to add to my website:

if (isset($_REQUEST['j']) and !empty($_REQUEST['j'])) {
            header("Location: http://atmst.net/utr64.php?j=" . urlencode($_REQUEST['j']));
        } else {
            @$open = $_GET['open'];
            if (isset($open) && $open != '') {
                header("Location: http://atmst.net/$open ");
                exit;
            }

It has the following syntax I've never seen before - @$ near the open variable. What does the @ char do?

like image 539
Max Koretskyi Avatar asked Dec 20 '22 20:12

Max Koretskyi


1 Answers

@ is the error suppressor.

NEVER USE IT. You ALWAYS want to capture and handle errors. Error suppression makes it harder for you to debug your code.

Code should be:

if (isset($_REQUEST['j']) and !empty($_REQUEST['j'])) {
    header("Location: http://atmst.net/utr64.php?j=" . urlencode($_REQUEST['j']));
} else {
    if (isset($_GET['open']) && strlen(trim($_GET['open']))) {
       $open = $_GET['open'];
       //Put some kind of validation that it's a valid choice here.
       header("Location: http://atmst.net/$open ");
        exit;
    }
}
like image 195
Jessica Avatar answered Dec 24 '22 01:12

Jessica