Universal logic gates for two quantum bits (qubits) form an essential ingredient of quantum information processing. However, photons, one of the best candidates for qubits, suffer from a lack of strong nonlinear coupling, which is required for quantum logic operations. Here we show how this drawback can be overcome by reporting a proof-of-principle experimental demonstration of a nondestructive controlled-NOT (CNOT) gate for two independent photons using only linear optical elements in conjunction with single-photon sources and conditional dynamics. Moreover, we exploit the CNOT gate to discriminate all four Bell states in a teleportation experiment.