J. Doe J. Doe - 9 months ago 20
PHP Question

If GET isn't ... or if GET is empty

I want to add

class sidebg
when the user doesn't visit the page 'wijzigpagina' or if the
$_GET page
is empty.

I tried adding
&& empty($_GET["page"])

<div id="wrapper"<?php if(isset($_GET["page"]) && $_GET["page"] !== "wijzigpagina" && empty($_GET["page"])) { echo ' class="sidebg"'; } ?>>

But that didn't work.


Just code exactly what you said:

if (empty($_GET['page']) || $_GET['page'] != "wijzigpagina")

If $_GET['page'] is set and has a non-false value, the second part of the OR expression will be evaluated and check if the value is not equal to "wijzigpagina". So any values of $_GET['page'] other than "wijzigpagina" will add your class.