What are some common pitfalls to be aware of when dealing with links in PHP forums?

One common pitfall when dealing with links in PHP forums is not properly sanitizing user input before using it in a link. This can leave the forum vulnerable to cross-site scripting attacks. To prevent this, always use functions like htmlspecialchars() to escape user input before outputting it as a link.

// Sanitize user input before using it in a link
$userInput = $_POST['user_input'];
$sanitizedInput = htmlspecialchars($userInput);

echo "<a href='https://example.com/?search=" . $sanitizedInput . "'>Search</a>";