We study finite time blow-up and global existence of solutions to the Cauchy problem for the porous medium equation with a variable density $rho(x)$ and a power-like reaction term. We show that for small enough initial data, if $rho(x)sim frac{1}{left(log|x|right)^{alpha}|x|^{2}}$ as $|x|to infty$, then solutions globally exist for any $p>1$. On the other hand, when $rho(x)simfrac{left(log|x|right)^{alpha}}{|x|^{2}}$ as $|x|to infty$, if the initial datum is small enough then one has global existence of the solution for any $p>m$, while if the initial datum is large enough then the blow-up of the solutions occurs for any $p>m$. Such results generalize those established in [27] and [28], where it is supposed that $rho(x)sim |x|^{-q}$ for $q>0$ as $|x|to infty$.