redirect home page to another if user logged in php

Hey! I am wondering if you would like to help me with my php code. I want users to be redirected from home page to a custom page called “dashboard” if they are logged in. If not, then I want them to be able to enter the standard home page.

This is the code that I have come up with:

<?php if (is_user_logged_in() ) {
wp_redirect ( home_url("/dashboard") );

I have written it in header.php of my themes child. At the very top. When I try this code ill get an error. Something like “this page try to redirect you to many times” or something like that.

I would really appreciate your support! tnx