Cycle through list of links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
opsoyo
Forum Newbie
Posts: 1
Joined: Fri Jul 30, 2010 8:17 pm

Cycle through list of links

Post by opsoyo »

I would like to cycle through a list of links with PHP. And what I mean is if there are several links (mirrors) to a file and one of the links fails, to move on the list to the next link. Is this possible?
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Cycle through list of links

Post by JakeJ »

Check out tutorials of a for each loop. You'll need to add all of your links to an array and then cycle them through the loop and act on them inside of the loop.

Alternatively, if you have a variable assigned to each link, you can do use a switch/case statement.

I'm not sure which solution would work best for you.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Cycle through list of links

Post by superdezign »

opsoyo wrote:[If] one of the links fails, to move on the list to the next link. Is this possible?
Define "failing". If this is something that you can check for on the server side, then you'd need to reload the page with a different link upon each failure. If you can check for this on the client side, you could put all of the links in on the server-side, but hide them on the client-side until a failure occurs. Then, expose the next link.
Post Reply