Electric and Magnetic field's phase difference shift in linearly polarized electromagnetic waves I am a high school student and we currently studying the electromagnetic theory. In my textbook i read that the oscillating electric the magnetic fields have phase difference equal to π/2 rad near the source (for example an antenna) while away from it they agree in phase.
Is this true? And if so, why and how is this happening.
 A: Possibly you are talking about the difference between the "far field" and "near field" solutions for the simple oscillating electric dipole.
Often when dealing with such a system, if we are looking at the field more than a few wavelengths away from the dipole (or more formally, $kr \gg 1$ or $r \gg \lambda/2\pi$) then the solution looks like a spherically expanding electromagnetic wave; the E-field and B-field are in phase, mutually perpendicular and at right angles to the outward propagation direction. For a dipole moment aligned with the z-axis, the E-field is polarised in the $\theta$ (poloidal) direction and B-field is in the $\phi$ (toroidal) direction.
But if $r \leq \lambda$ then the solution is more complicated. The E-field has both a $\theta$ and a radial component. The B-field is just toroidal, but contains two terms with differing radial dependencies.
In these extra terms for the nearby fields, the E-field becomes much more dominant (in transverse electromagnetic waves it is normally $c$ times bigger). Furthermore it is out of phase with the B-field by $\pi/2$. You can see this from the equations below - when $r$ is small, the first term in $B_{\phi}$ dominates the B-field, whereas it is the first (even stronger) terms in the $E_r$ and $E_{\theta}$ components that dominate the E-field. 
These are different in magnitude from the B-field by a factor that includes $i$ and hence are out of phase by $\pi/2$.
Perhaps this is what you mean?
The Maths:
The solutions for the E- and B-field from a simple oscillating dipole are
$$E_{r} = \frac{p_0 \cos\theta}{4\pi \epsilon_0} \frac{k^2 \exp(ikr)}{r}\left[ \frac{2}{k^2r^2} - \frac{2i}{kr} \right]$$
$$E_{\theta} = \frac{p_0 \sin\theta}{4\pi \epsilon_0} \frac{k^2 \exp(ikr)}{r}\left[ \frac{1}{k^2r^2} - \frac{i}{kr}  -1 \right]$$
$$B_{\phi} = \frac{p_0 \sin\theta}{4\pi \epsilon_0} \frac{k^2 \exp(ikr)}{r}\left[ - \frac{i}{kr}  -1 \right] \left(\frac{\epsilon_0}{\mu_0} \right)^{1/2}$$
A: Let me explain the nearfield phase shift of π/2 by how an antenna work. The antenna is an open electrical "circuit" where a electrical generator push and pull electrons inside the antenna rod. And the antenna rod one can imagine as a capacitor with its electrical field.
How the electrical and the magnetic fields are produced, see here. During each half oscillation of the generator each free electron produces a photon which propagates as an electromagnetic wave with shifted by π/2 electrical and magnetic components. That's not magic, a lot of electrons produce Bremsstrahlung. The wavelength of these photons depends of the material of the rod and other influences too. The wavelength of the radio wave depends from the frequency of the generator and the velocity of light in air. (The right length of the antenna rod is helpful for the antenna efficency.)
More amazing is the fact that according to Maxwells equations this radio wave get transformed at some distance to the antenna rod into no shift of the electrical an magnetic component.
