Page 1 of 1

Cycle through list of links

Posted: Fri Jul 30, 2010 8:22 pm
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?

Re: Cycle through list of links

Posted: Sun Aug 01, 2010 2:48 am
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.

Re: Cycle through list of links

Posted: Sun Aug 01, 2010 7:58 am
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.