PDA

View Full Version : webserver connection check



blasius
04-06-2007, 10:00 AM
Hi guys,

Is it possible to:
after pressing a button on a website witch is redirecting to a new site,
before redirecting to the new site, first check if the website is available,
if not available >> do not try to redirect to the new site.

Just a method to see if the web server (or website) is available before trying to download it.

if possible >> how?

thanks!

boogyman
04-06-2007, 01:40 PM
umm that is basically asking it to connect 2 times?

tech_support
04-07-2007, 03:20 AM
You could use PHP to do that, but definitely not JavaScript.

Twey
04-07-2007, 10:07 AM
Actually, it can be done with Javascript. It shouldn't be, but it can.

mburt
04-07-2007, 10:38 AM
first check if the website is available,
How can that be done with JavaScript?

file_exists works with PHP, that's the only plausible way of doing it.

Twey
04-07-2007, 11:05 AM
How can that be done with JavaScript?If you have the address of an image on that site:
var im = document.createElement("img");
im.src = "http://www.someothersite.com/images/image.png";
im.onload = function() {
// The server is up.
};
im.onerror = function() {
// The connection timed out, the server
// isn't up (or there was a problem
// accessing the image requested).
};

shachi
04-07-2007, 11:12 AM
I think pear's Net_Ping package might help you.

http://pear.php.net/package/Net_Ping
http://builder.com.com/5100-6371-5234592.html

Twey
04-07-2007, 11:46 AM
Not necessarily... just because the host is up, doesn't mean the webserver is. mburt is right, fsockopen() or file_exists() (the latter requires url_fopen enabled) are the better choices.

mburt
04-07-2007, 02:07 PM
(the latter requires url_fopen enabled)
I swear. Every person who's ever been on the PHP forum has asked some sort of question involving this, at least ONCE. :)

Just a note for someone who's about to ask:
It's a command in your php.ini which is either, off or on. If it is on, it allows you to basically "connect" to other sites' data. If it's off, you're royally screwed.

boxxertrumps
04-07-2007, 02:13 PM
What reasons would there be for turning it off?

mburt
04-07-2007, 02:23 PM
You don't turn it off or on. You can't. It's your server configuration.

boxxertrumps
04-07-2007, 02:42 PM
But the configuration can be changed... correct? doesn't editing php.ini turn the features on/off? Am i missing something?

thetestingsite
04-07-2007, 02:50 PM
You can edit it in your php.ini file; however, some webhosts turn this off for security issues (or some other reasons). I think, by default, it is turned on.

mburt
04-07-2007, 02:50 PM
With W/LAMP you can change it. That's about it. If you get a webhost off the internet, it's set by your host. You often contact your webhosting service though, and ask them to change it. I read a post a while back where someone did.

Twey
04-07-2007, 03:51 PM
Not royally screwed, per se... you just have to use fsockopen() and do things the old-fashioned way rather than relying on URLs :)

mburt
04-07-2007, 05:11 PM
Yeah, and all the curl/ob functions.

shachi
04-08-2007, 05:52 AM
Each time I try to use fsockopen, my browser crashes. No clue why but I am sure it wasn't supposed to happen. :(

Twey
04-08-2007, 11:31 AM
Err? It runs on the server, it shouldn't have any impact on your browser...

shachi
04-08-2007, 01:06 PM
Yea, I know that, that's why I wrote:


but I am sure it wasn't supposed to happen

But still, it kinda like freezes my browser.

Twey
04-08-2007, 01:12 PM
You're sure the page doesn't just take a long time to load?

shachi
04-08-2007, 02:53 PM
Actually, it doesn't load at all.