Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 12-08-2010, 02:12 PM   #1
klinton
So Fucking Banned
 
Industry Role:
Join Date: Apr 2003
Location: online
Posts: 8,766
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 ?
klinton is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:19 PM   #2
myneid
Confirmed User
 
myneid's Avatar
 
Industry Role:
Join Date: Jan 2003
Location: Los Angeles
Posts: 736
thats kind of like saying that your car doesnt work whats wrong with it, without giving the specifics
__________________
Tanguy 0x7a69 inc. Programmer/President/CEO
http://www.0x7a69.com
A Leader in Programming since 1996
PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting
myneid is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:30 PM   #3
klinton
So Fucking Banned
 
Industry Role:
Join Date: Apr 2003
Location: online
Posts: 8,766
<?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....
klinton is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:35 PM   #4
Serge Litehead
Confirmed User
 
Serge Litehead's Avatar
 
Industry Role:
Join Date: Dec 2002
Location: Behind the scenes
Posts: 5,190
perhaps count($urls) needs -1
count($urls)-1
__________________
Serge Litehead is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:38 PM   #5
Serge Litehead
Confirmed User
 
Serge Litehead's Avatar
 
Industry Role:
Join Date: Dec 2002
Location: Behind the scenes
Posts: 5,190
when debugging you can print out url and random number vars and see where problem lays
__________________
Serge Litehead is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:41 PM   #6
myneid
Confirmed User
 
myneid's Avatar
 
Industry Role:
Join Date: Jan 2003
Location: Los Angeles
Posts: 736
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
__________________
Tanguy 0x7a69 inc. Programmer/President/CEO
http://www.0x7a69.com
A Leader in Programming since 1996
PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting
myneid is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:50 PM   #7
klinton
So Fucking Banned
 
Industry Role:
Join Date: Apr 2003
Location: online
Posts: 8,766
so i should add this line somewhere :-P ???

count($urls)-1 ??

where ;-) ?

edit: ups now i see it...

THANKS !!!

Last edited by klinton; 12-08-2010 at 02:52 PM..
klinton is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:53 PM   #8
myneid
Confirmed User
 
myneid's Avatar
 
Industry Role:
Join Date: Jan 2003
Location: Los Angeles
Posts: 736
actually i take that back, dont do the $count-1
instead cahnge this line to this
header("location:" . $urls[$random-1]);
__________________
Tanguy 0x7a69 inc. Programmer/President/CEO
http://www.0x7a69.com
A Leader in Programming since 1996
PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting
myneid is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 02:56 PM   #9
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
Quote:
Originally Posted by myneid View Post
actually i take that back, dont do the $count-1
instead cahnge this line to this
header("location:" . $urls[$random-1]);
nope, that can result in -1 your first suggestion was ok

replace
$random = rand(0,count($urls));
with
$random = rand(0,count($urls)-1);
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 03:04 PM   #10
myneid
Confirmed User
 
myneid's Avatar
 
Industry Role:
Join Date: Jan 2003
Location: Los Angeles
Posts: 736
ha! yea looks like the sudafed is affecting my judgement more than i previously thought
__________________
Tanguy 0x7a69 inc. Programmer/President/CEO
http://www.0x7a69.com
A Leader in Programming since 1996
PHP, Ruby on Rails, MySQL, PCI DSS, and any Technical Consulting
myneid is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 03:06 PM   #11
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
Quote:
Originally Posted by myneid View Post
ha! yea looks like the sudafed is affecting my judgement more than i previously thought
i know exactly what you mean
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 03:10 PM   #12
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
Quote:
Originally Posted by grumpy View Post
nope, that can result in -1 your first suggestion was ok

replace
$random = rand(0,count($urls));
with
$random = rand(0,count($urls)-1);
What he said...
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-08-2010, 03:19 PM   #13
woj
<&(©¿©)&>
 
woj's Avatar
 
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
using array_rand is probably more straightforward...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-09-2010, 09:06 PM   #14
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085
Quote:
Originally Posted by woj View Post
using array_rand is probably more straightforward...
Certainly takes out some minor overhead by calling count() manually for each parse. I'd suggest this as well for something as simple-tarded as mentioned.

Code:
<?php
$urls = array(
        'http://www.google.com',
        'http://www.msn.com',
        'http://www.bing.com',
        'http://www.webcrawler.com',
        'http://www.dogpile.com',
);
header("location: ". array_rand(array_flip($urls), 1));
?>
__________________
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 12-09-2010, 09:22 PM   #15
Tempest
Too lazy to set a custom title
 
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
Quote:
Originally Posted by GrouchyAdmin View Post
Certainly takes out some minor overhead by calling count() manually for each parse. I'd suggest this as well for something as simple-tarded as mentioned.

Code:
<?php
$urls = array(
        'http://www.google.com',
        'http://www.msn.com',
        'http://www.bing.com',
        'http://www.webcrawler.com',
        'http://www.dogpile.com',
);
header("location: ". array_rand(array_flip($urls), 1));
?>
Or he could just do a shuffle.

Code:
<?php
$urls[] = "url1";
$urls[] = "url2";
$urls[] = "url3";
$urls[] = "url4";
$urls[] = "url5";

shuffle($urls);

header('location: '.$urls[0]);
?>
Gotta love how's there multiple solutions to the same thing.
Tempest is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.