By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,272 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,272 IT Pros & Developers. It's quick & easy.

How can I verify if a domain redirect to another?

P: 4
How can I verify if a domain redirect to another site? for html xml xhtml etc.
Jan 21 '10 #1
Share this Question
Share on Google+
7 Replies

Expert 5K+
P: 5,058

I suppose you could use the get_headers function to check the HTTP headers the domain returns. If the response gives you a 30x status code, it is redirecting you to another location.

The return data from the function would include these two elements, which you could use to determine if, and where to, it is redirecting you.
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [0] => HTTP/1.1 302 Found
  4.     [3] => Location:
  5. )
Jan 21 '10 #2

P: 4
There are a lot of problems with get_headers. I need a little script wich can return four values: 0 - if domain is not online, 1 - if is online , 2 - if redirect, and new domain if redirect. I have 1800 domain to check. I need to be sure for all kind of servers.
Jan 27 '10 #3

Expert 5K+
P: 5,058
Ok, what you have tried so far?
What problems are you facing?

We won't write the script for you, but we are more than happy to help you write it.
Jan 27 '10 #4

Expert 100+
P: 1,044
Your server is most likely to know the information that you are looking for. PHP is just an intermediary for programmers to their server. If the headers aren't doing it for you, then look online for the type of server you have and how it handles responses.
Jan 27 '10 #5

P: 4
Yes, but all domain are websites on different servers in world.
Jan 27 '10 #6

Expert 100+
P: 1,044
So? You're gonna need to be more clear about what you are trying to accomplish. If you are using your server to send a request, you WILL receive a response. That's how you know what your user would expect as a response when they are redirected. If you want some way of knowing information AFTER the redirection has occurred, you'd need access to the other server.
Jan 27 '10 #7

Expert 5K+
P: 5,058
That's not really true. A domain just points to an IP address. It doesn't necessarily have to have anything to do with a website.

But anyways, to accomplish what you are trying to do (or at least what I think you are trying to do) you just need to follow a fairly simple process.

Consider this pseudo-code (PHPseudo-code, if you will :P):
Expand|Select|Wrap|Line Numbers
  1. if( HEAD request was successfull ){
  2.     if( Status code is 200 ){
  3.         // Server is online and not redirecting you.
  4.     }
  5.     else if( Status code is 300-399 ){
  6.         $location = Location header
  7.         // Server is online and redirecting you to $location.
  8.     }
  9.     else {
  10.         // Server is online and not redirecting you,
  11.         // but the request was not successful.
  12.     }
  13. else {
  14.     // Server is offline.
  15. }
That could be the skeleton of your script. You just need to fill it in with working code.

You can either do this by using the get_headers function I mentioned earlier, or by sending the request by some other means. (Curl, Sockets, etc...)
Jan 27 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.