![]() |
All you clever coder types ! Beginners PHP Question
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 ! |
Quote:
|
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. |
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]"); ?> |
Quote:
PHP Code:
|
Man this is crazy!!
|
You tricky script kiddies you...
|
wanna sell those clicks? lol
|
Code:
$urls = file('urls.txt'); |
Quote:
|
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 |
See sig. :)
|
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) { |
Quote:
Quote:
|
Quote:
Code:
<?php |
ok which one of you guys knows nats and is looking for work? :)
|
Quote:
|
Quote:
|
Quote:
|
lol - you guys are going to be measuring dicks before this thread is through!
|
Quote:
|
wait, let me try this
PHP Code:
|
Quote:
Code:
<?php |
Quote:
|
Quote:
|
Hey, assholes.
count() positive indexes starts at one (0 == FALSE (when not === tested)). arrays start at zero. |
Quote:
|
Quote:
|
n00bs, every last one of ya
|
Quote:
|
Quote:
FOCUS, GOD DAMN IT! |
:( :( :(
|
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. |
count($cockinches[$GrouchyAdmin]) starts and ENDS at zero.
Ooooh nerd burn. |
Quote:
|
Quote:
|
<? echo "Hello World!!!"; ?>
You can thank me later. ;) |
You all fail at speed optimization with your over-engineered solutions :1orglaugh
Array solution is over 20 times faster than file cache solution which is already 3 times faster than memcache solution, so all of you :321GFY |
switch to mt_rand already
also, seeding is mostly useless |
Quote:
|
Quote:
|
Congratulations - 300 lines of code to rotate 5 links.
|
Quote:
|
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 :) |
does it have a section on poop?
|
Quote:
:) Please note: When I'm posting serious threads, I post sig free :) |
Quote:
|
Quote:
|
Quote:
|
| All times are GMT -7. The time now is 07:52 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123