Join 105,763 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,684 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!
I don't know if this is the right place to put this, but this is the best place I see.
Right now, I am unable to run my web servers 24/7, I was wondering if there would be a way to have a jscript or php that would detect if my server is up or not, and if it is not, to go to another website which has a message that alerts visitors that my servers are not running at the time, I have seen other sites do such things, but I can figure out how they are doing it.
The only way I can think of to do that is if you store a php page on some server -- a free one maybe -- that checks if your server is offline or not using a ping request maybe. If your server times out it will not redirect, and will just say that your server is unavailable at the time. And if the server is online it will redirect the user using the header("Location: www.example.com") function call. But that doesn't make too much sense to me, because if you could get a page on a server, why would you need to redirect to another server?...
Bottom line is, you can't really do anything else with php or javascript/html of this nature, simply because to run php you need the server to compile it and send the result as HTML to the user! But if the server is offline, no requests could be made, so it can't send anything back to the user.
I would suggest doing some research on how the all domain system and licensing works, how does the user get sent to a given domain/ip, how is the users request dispatched and by who. Probably there are services out there that allow you to do this, you should look there. Sorry I could not help you more; I am not really familiar with the details of how the internet and http requests work.
The only way I can think of to do that is if you store a php page on some server -- a free one maybe -- that checks if your server is offline or not using a ping request maybe. If your server times out it will not redirect, and will just say that your server is unavailable at the time. And if the server is online it will redirect the user using the header("Location: www.example.com") function call. But that doesn't make too much sense to me, because if you could get a page on a server, why would you need to redirect to another server?...
Bottom line is, you can't really do anything else with php or javascript/html of this nature, simply because to run php you need the server to compile it and send the result as HTML to the user! But if the server is offline, no requests could be made, so it can't send anything back to the user.
I would suggest doing some research on how the all domain system and licensing works, how does the user get sent to a given domain/ip, how is the users request dispatched and by who. Probably there are services out there that allow you to do this, you should look there. Sorry I could not help you more; I am not really familiar with the details of how the internet and http requests work.
The company that sells the domain names gives you 25 megabytes to store some files on, I am looking for a way that can re-direct to my web server at my house, if they are online. otherwise, to echo an error message to the user. (It's really a pain, when you are trying to access a server, and can't get any info!)
Here is a quick modification to the php code that you might want to use:
CODE
$ip = "127.0.0.1"; // your server's ip address
$sock = fsockopen($ip , 80, $errno, $errstr, 5 );
if ( ! $sock ) { echo "Sorry our server seems to be down at this moment, please try again later"; } else { // redirect to your server header("Location: http://$ip"); }
This should work. You might also want to read php manual documentation on those two functions, fsockopen and header.
This post has been edited by Mike007: 2 Feb, 2008 - 04:28 PM
Right now, I am unable to run my web servers 24/7, I was wondering if there would be a way to have a jscript or php that would detect if my server is up or not...
If your server is not running, where do you intend to put this code?
If you are not running your own DNS, then I would say that no, you cannot do this. The places that have a "we are temporarily down" can do this, because they receive the incoming traffic & forward them based on the status of the webserver(s).
The only way I can think of to do that is if you store a php page on some server -- a free one maybe -- that checks if your server is offline or not using a ping request maybe. If your server times out it will not redirect, and will just say that your server is unavailable at the time. And if the server is online it will redirect the user using the header("Location: www.example.com") function call. But that doesn't make too much sense to me, because if you could get a page on a server, why would you need to redirect to another server?...
Bottom line is, you can't really do anything else with php or javascript/html of this nature, simply because to run php you need the server to compile it and send the result as HTML to the user! But if the server is offline, no requests could be made, so it can't send anything back to the user.
I would suggest doing some research on how the all domain system and licensing works, how does the user get sent to a given domain/ip, how is the users request dispatched and by who. Probably there are services out there that allow you to do this, you should look there. Sorry I could not help you more; I am not really familiar with the details of how the internet and http requests work.
The company that sells the domain names gives you 25 megabytes to store some files on, I am looking for a way that can re-direct to my web server at my house, if they are online. otherwise, to echo an error message to the user. (It's really a pain, when you are trying to access a server, and can't get any info!)
-Thanks for your help!
This post has been edited by aj32: 6 Feb, 2008 - 01:50 PM
The company that sells the domain names gives you 25 megabytes to store some files on, I am looking for a way that can re-direct to my web server at my house, if they are online. otherwise, to echo an error message to the user. (It's really a pain, when you are trying to access a server, and can't get any info!)
-Thanks for your help!
http://us.php.net/manual/en/function.fsockopen.php Use fsockopen to open a connection with port 80 of your website. If it fails, then there is a good chance that the site is down. Otherwise... forward the traffic.
The company that sells the domain names gives you 25 megabytes to store some files on, I am looking for a way that can re-direct to my web server at my house, if they are online. otherwise, to echo an error message to the user. (It's really a pain, when you are trying to access a server, and can't get any info!)
-Thanks for your help!
http://us.php.net/manual/en/function.fsockopen.php Use fsockopen to open a connection with port 80 of your website. If it fails, then there is a good chance that the site is down. Otherwise... forward the traffic.
yea, I'm using the fsockopen code that Mike007 gave me, It works fine.