Welcome to Dream.In.Code
Getting Help is Easy!

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!



Automatic Redirection

 
Reply to this topicStart new topic

Automatic Redirection

aj32
post 29 Jan, 2008 - 05:27 PM
Post #1


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


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.

Thank you for you help! smile.gif
User is offlineProfile CardPM

Go to the top of the page


Mike007
post 29 Jan, 2008 - 06:05 PM
Post #2


D.I.C Head

Group Icon
Joined: 30 Aug, 2007
Posts: 200



Dream Kudos: 75
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

aj32
post 1 Feb, 2008 - 01:28 PM
Post #3


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


QUOTE(Mike007 @ 29 Jan, 2008 - 08:05 PM) *

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!
User is offlineProfile CardPM

Go to the top of the page

MorphiusFaydal
post 1 Feb, 2008 - 05:49 PM
Post #4


D.I.C Addict

Group Icon
Joined: 12 May, 2005
Posts: 971



Thanked 3 times

Expert In: Hardware, Networking

My Contributions


You could probably do it with a neat little bit of PHP.
User is online!Profile CardPM

Go to the top of the page

Mike007
post 2 Feb, 2008 - 04:26 PM
Post #5


D.I.C Head

Group Icon
Joined: 30 Aug, 2007
Posts: 200



Dream Kudos: 75
My Contributions


Here quick google found me this:
http://www.phpfreaks.com/quickcode/Server-...-Script/296.php

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
User is offlineProfile CardPM

Go to the top of the page

aj32
post 2 Feb, 2008 - 07:46 PM
Post #6


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


Thanks, Mike007, that did the job!
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 6 Feb, 2008 - 05:55 AM
Post #7


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,708



Thanked 25 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


QUOTE(aj32 @ 29 Jan, 2008 - 05:27 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).
User is online!Profile CardPM

Go to the top of the page

aj32
post 6 Feb, 2008 - 01:50 PM
Post #8


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


QUOTE(aj32 @ 1 Feb, 2008 - 03:28 PM) *

QUOTE(Mike007 @ 29 Jan, 2008 - 08:05 PM) *

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
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 8 Feb, 2008 - 05:51 AM
Post #9


Wet D.I.C.

Group Icon
Joined: 10 May, 2007
Posts: 4,708



Thanked 25 times

Dream Kudos: 2325

Expert In: Goofing Off

My Contributions


QUOTE(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.
User is online!Profile CardPM

Go to the top of the page

aj32
post 8 Feb, 2008 - 01:21 PM
Post #10


D.I.C Addict

Group Icon
Joined: 30 Aug, 2007
Posts: 577



Thanked 2 times

Dream Kudos: 675
My Contributions


QUOTE(no2pencil @ 8 Feb, 2008 - 07:51 AM) *

QUOTE(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.


yea, I'm using the fsockopen code that Mike007 gave me, It works fine.

-Thanks! biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 01:52PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month