PHP Redirect Within website
Question by baburao113
I’ve been trying this code since 3 days in a row until a certain time (minutes or seconds) but unable to solve the problem.
My target is to redirect visitor to 10 random URLs which are being selected from a text file. The user will see a certain page for a certain time and then redirect to another page again, the number of pages he will be redirected to is complete RANDOM.
PROBLEM:
The problem is the visitor is not being redirected to any other page which is randomly selected from a text file, instead it is just refreshing the page… But I want to redirect him to other pages from the text file.. Hope you guys understood me by now.
EDIT: Found the problem. Actually the $rand_link is having NULL as it’s value.. { [0]=> NULL } Don’t know why…. ANy solution? Checked the ‘BBnormalLinks.txt’ file for it’s permissions and that file is having some links in it for sure because I just checked it..
Thanks,
Here is the CODE:
<?php // Generate Random Nubmers.. 2 ********
$numbers2 = range(13,70);
shuffle($numbers2);
for ($j=0;$j<1;$j++)
{
$numbers2[$j];
}
$seconds = numbers2[0];
//////// For Random URL of Site
$links = file('BBnormalLinks.txt');
$rand_link = $links[ mt_rand(0, count($links) - 1) ];
header("refresh:". $seconds .";url=". $rand_link); ?>
Answer by Starx
The syntax is correct but some pointers that can cause this are
- Some text have been outputted before the header is passed.
- The random page, is not being generated, thus ending up refreshing the same page again and again.
I have a very strong feeling, that your $rand_link
is returning blank or null.
Update:
After a few discussion, the problem was the evil path
again.
$links = file('patotofileBBnormalLinks.txt');
As baburao113, quoted
I had to move that file to wordpress theme folder lol! Problem resolved 🙂