![]() |
php redirect shows blank page
hey, i setup some php rotation redirect...It should redirects people to some url from list.
however i see now, that it returns blank page every now and then...and i had to refresh page to get redirection...why is that ? |
thats kind of like saying that your car doesnt work whats wrong with it, without giving the specifics
|
<?php
$urls[] = "url1"; $urls[] = "url2"; $urls[] = "url3"; $urls[] = "url4"; $urls[] = "url5"; srand ((double) microtime( )*1000000); $random = rand(0,count($urls)); header("location:" . $urls[$random]); exit; ?> it sometimes redirects&rotate url,sometimes just show blank page.... |
perhaps count($urls) needs -1
count($urls)-1 |
when debugging you can print out url and random number vars and see where problem lays :2 cents:
|
yea thats what it is you need count($urls)-1 because count returns the number of elements in teh array but the array is indexed starting at 0
|
so i should add this line somewhere :-P ???
count($urls)-1 ?? where ;-) ? edit: ups now i see it... THANKS !!! :) |
actually i take that back, dont do the $count-1
instead cahnge this line to this header("location:" . $urls[$random-1]); |
Quote:
replace $random = rand(0,count($urls)); with $random = rand(0,count($urls)-1); |
ha! yea looks like the sudafed is affecting my judgement more than i previously thought
|
Quote:
|
Quote:
|
using array_rand is probably more straightforward... :2 cents:
|
Quote:
Code:
<?php |
Quote:
Code:
<?php |
All times are GMT -7. The time now is 08:42 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123