How to check url exist or can be opened or not, if not then

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
weixin268
Forum Newbie
Posts: 15
Joined: Mon Feb 17, 2014 12:53 am

How to check url exist or can be opened or not, if not then

Post by weixin268 »

How to check url exist or can be opened or not, if not then open alternative link.

e.g.

<? php
if exist(<a href="http://www.server1.com/link.php")Link</a>)
else (<a href="http://www.server2.com/link.php")Link</a>)
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to check url exist or can be opened or not, if not t

Post by requinix »

More information would be great. What are these servers? Do you control them? Where are these URLs coming from?
weixin268
Forum Newbie
Posts: 15
Joined: Mon Feb 17, 2014 12:53 am

Re: How to check url exist or can be opened or not, if not t

Post by weixin268 »

As sometimes, the server1 will down or cannot be connected, then user can open server2 link, all the pages are same.

http://www.server1.com/link.php cannot open or reach
try http://www.server2.com/link.php

But user only need to click one link

<a href=".........">Link</a>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to check url exist or can be opened or not, if not t

Post by requinix »

Okay, progress. How about the rest of my questions? And why might these servers be down? Is it possible for a server to be up but the link to still not work?

By the way, I'm not asking because I want to be difficult. I'm asking because the answers will help you get the best solution for your problem.
weixin268
Forum Newbie
Posts: 15
Joined: Mon Feb 17, 2014 12:53 am

Re: How to check url exist or can be opened or not, if not t

Post by weixin268 »

Okay, here is the reasons why. Actually the first link want the user(s) to connect is for security issues. If user(s) at office network, click on Link will open the first link for them (i.e. http://192.168.0.x/link.php). When the user(s) are out of office, when they click on the Link then will open the external link for them (http://www.domain.com/link.php). Actually they are pointing to the same server, same page.
Post Reply