Long gamma-ray bursts (GRBs) are associated with the explosion of massive stars in star forming regions. A large fraction of GRBs show intrinsic absorption as detected in optical spectra but absorption signatures are also detectable in afterglow X-ray spectra. We present here a comprehensive analysis the full sample of 93 GRBs with known redshift promptly observed by Swift XRT up to June 2009. The distribution of X-ray column densities clearly shows that GRBs are heavily absorbed indicating that they indeed occur in dense environments. Furthermore, there is a lack of heavily absorbed GRBs at low redshift (z<1-2) that might therefore be candidates for the missing `dark' GRB population. However, there is no statistically significant correlation between the amount of X-ray absorption and the `darkness' of a GRB. Finally, we compare the hydrogen column densities derived in the optical with those derived from X-ray absorption. The two distributions are different, with the optical column densities being lower than the X-ray ones, which is even more apparent when correcting for metallicity effects. The most likely explanation is photoionization of hydrogen in the circumburst material caused by the radiation field of the burst.