It's also used to mean he's manipulating you pyschologically.
If there's a song you can't get out of your head, you can't stop thinking about.
If some guy has gotten into your head, you MAY be thinking about him constrantly, or you MAY be a bit under his control because he knows how to affect your thinking and get you to do what he wants.