Cats rub against your legs as a form of marking their territory with scent glands located on their face and body. This behavior is a way for them to claim you as their own and to mix scents, creating a sense of familiarity and bonding between you and your feline friend.