I’m trying to define a link based of a $_GET variable, but it’s saying there’s an error on a line that doesn’t exist…
<?php
if(isset($_GET['ref'])){
if(!empty($_GET['ref']))
{
$ref = $_GET['ref'];
}
?>
<?php
if ($ref != "") {
$link = "http://site.com/page.php?ref=$ref";
} else {
$link = "http://site.com/page.php";
}
?>
Anyone see what’s up? I was pretty sure it was fine.
I’ve tried it multiple different ways, with isset etc… same result.
You are missing a closing
}:By the way, this code is quite redundant.
empty()will also check whether the variable is set, so you don’t needisset().You can also use the ternary operator, which is for cases like this:
And later check with:
Otherwise, in your code, when execution reaches
if ($ref != "") {, the variable$refmight not even exist – this will throw anE_NOTICE, which you might not even see, depending on your settings.