 <p>Without knowing the contents of 'BBnormalLinks.txt' or the final value of $rand_link, it is difficult to say precisely what is going wrong.</p> <p>Your usage of <code>file()</code> and <code>mt_rand()</code> appear to be correct, though you aren't doing anything to ensure that you are getting a valid URL. </p> <p>This is purely conjecture, but I suspect that you don't have PHP properly configured to display errors. If the file fails to load, $links will have a null value going into your penultimate line. You will then try to access element 0 of a null array and receive an empty value. This will result in <code>header('refresh:2;url=')</code> and your page will simply refresh itself every 2 seconds.</p>