Why does a cat rub up against your leg when it greets you?

 

Partly to make friendly physical contact with you, but there is more to it than that. The cat usually starts by pressing against you with the top of its head or the side of its face, then rubs all along its flank and finally may slightly twine its tail around you. After this it looks up and then repeats the process, sometimes several times. If you reach down and stroke the animal, it increases its rubbing, often pushing the side of its mouth against your hand, or nudging upwards with the top of its head. Then eventually it wanders off, its greeting ritual complete, sits down and washes its flank fur.
All these elements have special meanings. Essentially what the cat is doing is implementing a scent-exchange between you and it. There are special scent glands on the temples and at the gape of the mouth.
Another is situated at the root of the tail. Without your realizing it, your cat has marked you with its scent from these glands. The feline fragrances are too delicate for our crude noses, but it is important that friendly members of the cat's family should be scent-sharing in this way. This makes the cat feel more at home with its human companions. And it is important, too, for the cat to read our scent signals. This is achieved by the flank-rubbing element of the greeting, followed by the cat sitting down and 'tasting' us with its tongue through the simple process of licking the fur it has just rubbed so carefully against us.