How do PAPI lights work?
Here's how the PAPI lights work:

Depending on the angle of the viewer, a different color is seen:


Then each light is calibrated to an angle:


The good thing about this is that it's dead simple technology where very few things can go wrong: The lights have to be on and calibrated for the correct angle. The downside is that its usefulness decreases with lower visibility.

Some new systems appear to have solar panels as an off grid (and alternative/backup) power source which is sensible. Many systems today also have LED lights.


  If two airplanes with two different altitudes approach, do they see different number of white and red lights? Or are the lights set for the closer airplane?


The system is independent and passive, in the sense that it never makes contact or note of the aircraft approaching. It lights up all to all aircraft in the beam. Hence, it 'works' for all aircraft at the same time. 

Some new systems feature FAROS (Final Approach Runway Occupancy Signal) giving an indication that the runway may be occupied by another aircraft by flashing the lights.

For a little information on differences between similar systems to PAPI, see this link.