|
|
|
||||
|
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. |
![]() |
|
|||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
|
Thread Tools |
|
|
#1 |
|
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,676
|
Just starting 'learning' PHP...
Can a more experienced coder show me the way? What Im looking to do, is to have a sig on a surfer forum that reads 'CLICK HERE! LUCKY DIP!' They click the link it goes to one-of-my-domians.com/php-page.php That php page has 3 or 5 different URLs programmed into it... ie domain-1.com/blog/ domain-2.com/sexygirls/index.html and domain-3.com etc etc... When the sig clicking surfer hits the php page at one-of-my-domians.com/php-page.php it randomly chooses one of the 3 or 5 domains, and sends him to it... In other words, per click each domain has a 1 in 3 or 1 in 5 chance of getting the 'hit'... I'm not interested in 'Weighting' the results... Im just trying to learn the simplest, cleanest way to use PHP to split the results 'randomly' ? Whats the right PHP to do this a simple as poss? Be gentle with me LOL I'm genuinely TRYING to learn, and we all have to start somewhere ! |
|
|
|
|
|
#2 | |
|
Confirmed User
Join Date: Oct 2007
Posts: 138
|
Quote:
|
|
|
|
|
|
|
#3 |
|
Viva la vulva!
Join Date: Mar 2003
Location: you can't please everyone, so you got to please yourself
Posts: 16,557
|
I do it like this:
<? $urls = file ("random.txt"); //replace with the name of your file srand(time()); $count = count($urls); $random = (rand()%$count); Header("Location: $urls[$random]"); ?> random.txt contains a list of URLs. You could put the URLs into an array in the code if you prefer. I have them in a separate file so I can use them from other code. Example is in my sig. ![]() |
|
|
|
|
|
#4 |
|
Chafed.
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
|
What mikey said, but if you don't wanna use a file for the urls, here's an easy way to do the arrray:
<? $linkArray[0]="http://www.google.com"; $linkArray[1]="http://www.yahoo.com.com"; srand(time()); $count = count($linkArray); $random = (rand()%$count); Header("Location: $linkArray[$random]"); ?> |
|
|
|
|
|
#5 | |
|
Confirmed User
Industry Role:
Join Date: Jul 2007
Location: Intraweb
Posts: 274
|
Quote:
PHP Code:
|
|
|
|
|
|
|
#6 |
|
ICQ: 197-556-237
Join Date: Jun 2003
Location: BRASIL !!!
Posts: 57,559
|
Man this is crazy!!
__________________
I'm just a newbie. |
|
|
|
|
|
#7 |
|
Do Fun Shit.
Industry Role:
Join Date: Dec 2004
Location: OC
Posts: 13,393
|
You tricky script kiddies you...
__________________
![]() “I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde |
|
|
|
|
|
#8 |
|
bored
Industry Role:
Join Date: Aug 2003
Location: PORNCMS.com
Posts: 4,782
|
wanna sell those clicks? lol
__________________
#
|
|
|
|
|
|
#9 |
|
Confirmed User
Join Date: Nov 2004
Location: scv
Posts: 2,299
|
Code:
$urls = file('urls.txt');
header("Location: " . array_rand($urls));
|
|
|
|
|
|
#10 |
|
. . .
Industry Role:
Join Date: Apr 2007
Location: NY
Posts: 13,724
|
__________________
__________________ Looking for a custom TUBE SCRIPT that supports massive traffic, load balancing, billing support, and h264 encoding? Hit up Konrad!
Looking for designs for your websites or custom tubesite design? Hit up Zuzana Designs Check out the #1 WordPress SEO Plugin: CyberSEO Suite |
|
|
|
|
|
#11 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
I was just notified about this thread and thought I would come in with what I use across my huge network of highly redundant traffic nodes. Advanced eyes only.
Code:
<?php
$domain_base_url = 'http://www.yourdomain.com/';
$randomized_urls = file($domain_base_url . 'files/urls.txt');
$urls = array();
foreach ((array)$randmized_urls as $url) {
if (validate_url_presence_exists($url) == "TRUE") {
$urls[] = $url;
}
}
if (empty($urls)) {
header('Location: ' . $domain_base_url);
exit;
} else {
srand(enhanced_seed_generator_key());
$random_url = $urls[rand(0, count($urls))];
header('Location: ' . $random_url);
exit;
}
function enhanced_seed_generator_key() {
$str = '';
$chars = str_split('abcdefghijklmnopqrstuvwxyz');
for ($i = 1; $i = 10; $i++) {
shuffle($chars);
$str .= $chars[rand(0, count($chars))];
}
return (float)(time() + (getmypid() * microtime())) + php_atoi_v2($str);
}
function php_atoi_v2($str) {
$total = 0;
foreach (str_split($str) as $chr) {
$total += ord($chr);
}
return (int)$total;
}
function validate_url_presence_exists($url) {
$ch = curl_init();
curl_setopt($ch, curlOPT_URL, $url);
curl_setopt($ch, curlOPT_NOBODY, true);
curl_setopt($ch, curlOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, curlOPT_FOLLOWLOCATION, true);
curl_setopt($ch, curlOPT_HEADER, true);
$res = curl_exec($ch);
curl_close($ch);
return false if $res === false;
$code = explode($res);
return $code[1] == '200' ? "TRUE" : "FALSE";
}
?>
|
|
|
|
|
|
#12 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
See sig.
__________________
|
|
|
|
|
|
#13 | |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Quote:
You need to add support for caching; you probably only need to poll once a day, right? Here, have some functions: Code:
function read_cachefile($url = FALSE) {
if (function_exists('file_get_contents')) {
$array = file_get_contents($url);
} else {
$array = "";
if (file_exists($url)) {
$fp = fopen($url, 'r');
while (!FEOF($fp)) {
$array .= fread($fp, 4096);
}
fclose($fp);
}
}
return ($array ? unserialize($array) : FALSE);
}
function beginDay($date = FALSE) {
$date = (isset($date)) ? strtotime($date) : time();
return date("U", mktime(0, 0, +1, date("m", $date), date("d", $date), date("Y", $date)));
}
__________________
|
|
|
|
|
|
|
#14 | ||
|
Confirmed User
Join Date: Feb 2007
Location: 418194907
Posts: 3,134
|
Quote:
Quote:
|
||
|
|
|
|
|
#15 | |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
Code:
<?php
### DEFINE MEMCACHE CONSTANTS
DEFINE('MEMCACHE_HOST', 'localhost');
DEFINE('MEMCACHE_PORT', 11211);
### THIS IS MY DOMAIN, PLZ DONT USE MY LINKS
$domain_base_url = 'http://www.mydomain.com/';
$randomized_urls = file($domain_base_url . 'files/urls.txt');
$urls = array();
foreach ((array)$randomized_urls as $url) {
if (!check_cache($url)) {
### MAKE SURE ITS ONLINE
if (validate_url_presence_exists($url) == "TRUE") {
$urls[] = $url;
add_cache($url);
}
} else {
$urls[] = $url;
}
}
if (empty($urls)) {
### EVERYONE LIKES HEAD // todo, get head
header('Location: ' . $domain_base_url);
exit;
} else {
srand(enhanced_seed_generator_key());
$random_url = $urls[rand(0, count($urls)-1)]; // BUG FIXED
header('Location: ' . $random_url);
exit;
}
### PASS MY SEED
function enhanced_seed_generator_key() {
$str = '';
$chars = str_split('abcdefghijklmnopqrstuvwxyz');
for ($i = 1; $i = 10; $i++) {
shuffle($chars);
$str .= $chars[rand(0, count($chars))];
}
return (float)(time() + (getmypid() * microtime())) + php_atoi_v2($str);
}
### PHP FAILURE
function php_atoi_v2($str) {
$total = 0;
foreach (str_split($str) as $chr) {
$total += ord($chr);
}
return (int)$total;
}
function validate_url_presence_exists($url) {
$ch = curl_init();
curl_setopt($ch, curlOPT_URL, $url);
curl_setopt($ch, curlOPT_NOBODY, true);
curl_setopt($ch, curlOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, curlOPT_FOLLOWLOCATION, true);
curl_setopt($ch, curlOPT_HEADER, true);
$res = curl_exec($ch);
curl_close($ch);
return false if $res === false;
$code = explode($res);
return $code[1] == '200' ? "TRUE" : "FALSE";
}
function check_cache($url) {
$memcache = get_memcache_object_balanced();
return $memcache->get($url);
}
function add_cache($url) {
$memcache = get_memcache_object_balanced();
$memcache->set($url, 1, 0, 86400);
}
### BALANCE THE LOAD??? TODO -- MAKE IT BALANCE
function get_memcache_object_balanced() {
$memcache = new Memcache;
$memcache->connect(MEMCACHE_HOST, MEMCACHE_PORT) or die ("Could not connect");
return $memcache;
}
|
|
|
|
|
|
|
#16 |
|
Confirmed User
Industry Role:
Join Date: May 2001
Posts: 9,240
|
ok which one of you guys knows nats and is looking for work?
|
|
|
|
|
|
#17 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
The brotherhoods knowledge can not be purchased, unless you have money, and hookers.
|
|
|
|
|
|
#18 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Are you trying to undercut me, bitch?! It's Money, Hookers, and Blow.
__________________
|
|
|
|
|
|
#19 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
I AM THE PUMPKIN KING.
|
|
|
|
|
|
#20 |
|
Confirmed User
Join Date: Nov 2001
Location: Redmond, WA
Posts: 2,727
|
lol - you guys are going to be measuring dicks before this thread is through!
|
|
|
|
|
|
#21 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
We already do that in the backroom at the shows
|
|
|
|
|
|
#22 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
wait, let me try this
PHP Code:
|
|
|
|
|
|
#23 | |
|
Mostly retired
Industry Role:
Join Date: Apr 2006
Location: UK
Posts: 3,231
|
Quote:
Code:
<?php
function nameHere() {
die("Error: I can't code for shit");
}
?>
__________________
|
|
|
|
|
|
|
#24 | |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Quote:
|
|
|
|
|
|
|
#25 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
|
|
|
|
|
|
#26 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Hey, assholes.
count() positive indexes starts at one (0 == FALSE (when not === tested)). arrays start at zero.
__________________
|
|
|
|
|
|
#27 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
|
|
|
|
|
|
#28 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
your weiner isn't optimized enough to get hard.
|
|
|
|
|
|
#29 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
n00bs, every last one of ya
|
|
|
|
|
|
#30 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Don't hate, just learn to code. Is that to much to ask?
|
|
|
|
|
|
#31 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
I'm not paying you to 'consult', I'm paying you to 'take three cocks in the rectal cavity'.
FOCUS, GOD DAMN IT!
__________________
|
|
|
|
|
|
#32 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
|
|
|
|
|
|
#33 | |
|
Confirmed User
Industry Role:
Join Date: May 2001
Posts: 9,240
|
Quote:
Hit me up on icq if you or grouchy is interested, I need a coder who can handle more than two days of working before he needs a two week break. |
|
|
|
|
|
|
#34 |
|
Chafed.
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
|
count($cockinches[$GrouchyAdmin]) starts and ENDS at zero.
Ooooh nerd burn. |
|
|
|
|
|
#35 |
|
Mostly retired
Industry Role:
Join Date: Apr 2006
Location: UK
Posts: 3,231
|
I admit it. I'm not even pro enough to get those two zeros in the noob tag...
__________________
|
|
|
|
|
|
#36 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
All you're gonna get is that $cockinches[$GrouchyAdmin] is not set. Not circumcised, either.
__________________
|
|
|
|
|
|
#37 |
|
Confirmed User
Join Date: Apr 2004
Location: NC
Posts: 8,323
|
<? echo "Hello World!!!"; ?>
You can thank me later. ;) |
|
|
|
|
|
#38 |
|
Confirmed User
Join Date: Aug 2004
Location: www.calidi.com
Posts: 102
|
You all fail at speed optimization with your over-engineered solutions
![]() Array solution is over 20 times faster than file cache solution which is already 3 times faster than memcache solution, so all of you ![]() |
|
|
|
|
|
#39 |
|
Will code for food...
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
|
switch to mt_rand already
also, seeding is mostly useless
__________________
|
|
|
|
|
|
#40 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
Holy shit, I thought you were dead... any updates on CJUltra man? I've defended that script so many times because of people assuming it was sending visitors to warez sites and shit because of your skim... wooo, update it or something man.
|
|
|
|
|
|
#41 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
You were so damn close, too.
__________________
|
|
|
|
|
|
#42 |
|
So Fucking Banned
Join Date: Apr 2007
Posts: 806
|
Congratulations - 300 lines of code to rotate 5 links.
|
|
|
|
|
|
#43 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
If you don't understand the awesomeness, you are in the wrong field.
|
|
|
|
|
|
#44 |
|
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,676
|
Update ! Just revisiting this thread to say thanks for all the replies... Even if I DID get totally lost towards the end LOL
I went with the Mikeyddddd solution in the end. I liked the idea of the seperate text file... You see, as opposed to just posting 'how do I do this?' and grabbing the first reply, copy pasting it, and going off on my merry way... I do actually want to learn, so I went out a bought (DONT LAUGH) a 'book' ? and have been reading it over the last few days... Now at least I understand (kinda) HOW it works... Anyway, I have it all working like a dream! So THANKS |
|
|
|
|
|
#45 |
|
MOBILE PORN: IMOBILEPORN
Join Date: Jan 2004
Location: Tinseltown NL
Posts: 16,502
|
does it have a section on poop?
|
|
|
|
|
|
#46 |
|
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,676
|
|
|
|
|
|
|
#47 |
|
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,676
|
|
|
|
|
|
|
#48 |
|
Confirmed User
Join Date: May 2005
Posts: 2,737
|
Your pooping is not optimized. You need to straighten your back to allow for maxium force.
|
|
|
|
|
|
#49 |
|
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
The last time a noob tried that, he shit out his whole spine.
__________________
|
|
|
|