PHP - 如何使用cookie中的值重定向到个人资料页面

I'm making a website that has a simple profile system.

All my profiles have a separate .php file with their id in a name like 1.php, 2.php and so on.

On index navigation bar, I have the option to go to persons own profile (my page requires login on every page so it will work fine).

That's is where my problem is. I need to take id from my cookies (1 for example) and use it to go to profile/1.php.

Since my navigation bar is made with HTML, I need to use href system to redirect, but href cant recognize code from PHP $id.

I tried to make separated redirect file but that gave me Cannot modify header information error.

Is there a way for me to make such mess work (just learning) or do I need to scrap that idea?

but href cant recognize code from PHP ($id).

You just start the PHP tag inside the href like so

<a href="profile/<?= $id ?>.php">My profile</a>