Cooperativeness is a defining feature of human nature. Theoreticians have suggested several mechanisms to explain this ubiquitous phenomenon, including reciprocity, reputation, and punishment, but the problem is still unsolved. Here we show, through experiments conducted with groups of people playing an iterated Prisoner's Dilemma on a dynamic network, that it is reputation what really fosters cooperation. While this mechanism has already been observed in unstructured populations, we find that it acts equally when interactions are given by a network that players can reconfigure dynamically. Furthermore, our observations reveal that memory also drives the network formation process, and cooperators assort more, with longer link lifetimes, the longer the past actions record. Our analysis demonstrates, for the first time, that reputation can be very well quantified as a weighted mean of the fractions of past cooperative acts and the last action performed. This finding has potential applications in collaborative systems and e-commerce.