Copyright law does not treat code snippets differently from libraries. In either case you must first have the right to use that code. Copyright does not only cover copies of works but also their public performance. So strictly speaking, even server-side projects need a license for the code snippets and need to follow the terms of that license.
You can use code snippets only if any of the following holds:
The snippet is so trivial that it is not covered by copyright protection (it fails to meet the threshold of originality). In particular, copyright only protects an expression of an idea (idea–expression divide). If you cannot express an idea differently, that expression is not protected. E.g. no one can claim copyright on the structure of a
package.json file, or to a popular programming idiom. Many snippets will fall under this category.
Your use of the snippet falls under a copyright exception such as fair dealing. While the UK's fair dealing concept might apply to private use, I don't think it applies to commercial projects.
You have obtained a license for the snippet from the snippet's copyright holder. Most open-source licenses just require you to provide attribution in all copies, but do not restrict public performance in any way (the exception being the AGPL).
The absence of a license means “all rights reserved”, not “free for all”. Any Stack Overflow contributions are licensed under the CC-BY-SA 3.0 license which is difficult to use in projects that are not licensed under GPLv3. It is therefore probably best to avoid code snippets with unclear licenses or with a CC-BY-SA 3.0 license.
Copyright does not only cover economic usage rights such as the right to make a copy, but also moral rights: the right of the author to be credited for their work under their preferred name. This right is typically unwaivable, regardless under what license or copyright exception you use the snippet. However, the author might also choose to be pseudonymous (e.g. a Stack Overflow username), anonymous, or have attribution retroactively removed (e.g. if they do not want to be associated with your website). Some open-source licenses also explicitly state that you may not frame the attribution in a way that looks like an endorsement of your product.
GDPR recognizes various reasons why processing of personal data might be lawful. Under Art. 6(1)(c) processing is lawful if the “processing is necessary for compliance with a legal obligation to which the controller is subject”. (You are the data controller.) Here, providing attribution is a legal obligation you have. Both the copyright and privacy laws agree as to what the rights of the data subject/copyright holder are: if you've attributed the wrong name you must correct that upon their request (e.g. if they want to be pseudonymous), and you must remove attribution upon request.
Disclaimer: I'm not very familiar with common law/UK law. If in doubt, the laws of your jurisdiction apply and not the general concepts in this answer. Also, most people do not care about licensing of snippets – small scale copyright infringement is extremely common. You will most likely be completely fine if you fail to provide attribution for snippets used in back-end code that you do not share.
I think it is best to only copy snippets that are clearly not copyright-protected, or to only copy the idea of the snippet rather than the snippet itself.