What potential pitfalls should be considered when using PHP to control the visibility of elements in a website?

Potential pitfalls when using PHP to control the visibility of elements in a website include security vulnerabilities if user input is not properly sanitized, potential performance issues if the logic is not optimized, and potential accessibility concerns if elements are hidden without providing alternative content for screen readers.

// Example of properly sanitizing user input to prevent security vulnerabilities
$userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : 0;
```

```php
// Example of optimizing logic to prevent performance issues
$isAdmin = checkIfUserIsAdmin(); // Assume this function checks if user is admin
if ($isAdmin) {
    // Show admin-only content
}
```

```php
// Example of providing alternative content for screen readers
if ($isVisible) {
    echo '<div>Visible content</div>';
} else {
    echo '<div style="position: absolute; left: -9999px;">Hidden content</div>';
}