What potential issues can arise when passing variables in a link in PHP?
One potential issue when passing variables in a link in PHP is that it can expose sensitive data to users or make the application vulnerable to injection attacks. To solve this issue, you should always sanitize and validate user input before using it in a link.
// Sanitize and validate user input before passing variables in a link
$userId = filter_var($_GET['user_id'], FILTER_SANITIZE_NUMBER_INT);
// Use the sanitized variable in the link
echo '<a href="profile.php?user_id=' . $userId . '">View Profile</a>';