Virtual photons are not real photons. They are just mathematical building blocks in the perturbative evaluation of S-matrix elements. The internal lines of Feynman diagrams do not represent photons or particles but the propagator of the quantum field (in the vacuum case the socalled Feynman propagator of perturbation theory, i.e., the vacuum expectation value of the time-ordered connected two-point field-correlation function).
Depending on the gauge the propgator can have four-longitudinal components. E.g., in Feynman gauge, which is the most convenient one for perturbative calculations, Feynman propagator for photons reads
$$\Delta_{\mu \nu}(p)=-\frac{g^{\mu \nu}}{p^2 + \mathrm{i} 0^+}.$$
There you seemingly have four components.
In Landau gauge your photon propagator is made four-transverse
$$\Delta_{\mu \nu} (p)=-\left ( g^{\mu \nu} - \frac{p^{\mu} p^{\nu}}{p^2 + \mathrm{i} 0^+} \right) \frac{1}{p^2+\mathrm{i} 0^+}.$$
Here you seemingly have 3 components (two 3-transverse and one 3-longitudinal).
These would-be degrees of freedom are not all observable, because you can only make sense of asymptotic free states in terms of observable objects, and here gauge invariance comes to the rescue! For on-shell S-matrix elements finally only the two physical 3-transverse field-degrees of freedom of the quantized electromagnetic field contribute. The unphysical degrees of freedom in the one or the other gauge are cancelling out. In the Abelian case as is QED, current conservation is necessary and sufficient for this cancellation, which is formally encoded in the so-called Ward-Takahashi identities for the proper vertex functions and the connected Green's functions. In non-Abelian gauge theories you need also Faddeev-Popov ghosts (and for Higgsed models also the would-be Goldstone modes in non-unitary gauges) to make this cancellation happen. Here, the Slavnov-Taylor identities substitute the Ward-Takahashi identies of the Abelian case. An exception is the socalled Background-Field Gauge, where the simple Ward-Takahashi identities become available again, and that simplifies the proof of the (perturbative) renormalizability of non-Abelian gauge theories considerably.