0

I have a the following URL:google.com.

I need to know if the full hostname consists www, or a function that will give me the full hostname (IE. www.google.com)

I want to get the full host-name and i cannot always add www as a prefix (IE. if i have docs.google.com, i don't want to add www because it will destroy the link).

Is there a way to know if i can add www as a prefix or not? I tried some of the PHP gethost() functions but no avail.

Ori Price
  • 3,593
  • 2
  • 22
  • 37
  • What do you mean by "full hostname"? Depending on how a site's DNS is set up `example.com` and `www.example.com` could be two completely different IPs/sites. (Heck, I could do `www.sub.example.com` if I wanted to.) If the link is `example.com`, then I'd just leave it as `example.com`. Why do you want to know if you can add `www`? – gen_Eric Oct 06 '15 at 20:39
  • cause i am using curl for a site and it doen't load resources well if i am fixing relative url to "example.com". on the other hand if i am fixing relative urls to "www.example.com" everything works like a charm. is it possible to get the dns setup for a url? – Ori Price Oct 06 '15 at 20:47
  • What *exactly* are you trying to do here? The *real* issue is probably elsewhere. – gen_Eric Oct 06 '15 at 20:49
  • 1
    i am using Curl scrapper for a site of exmaple.com. in order to present it locally in an iframe i am fixing all relative urls (IE - "/image/123.jpg" to "http://example.com/image/123.jpg"), this results in inconsistent behaviors regarding loading images. sometimes i get 503 for some images. BUT when i am fixing the relative URLs to a Full ones (IE - "http://www.example.com/image/123.jpg") i get no errors. so, for a given url i want to knwo what is its full host name. – Ori Price Oct 06 '15 at 20:55
  • The problem is that *both* `http://example.com/image/123.jpg` and `http://www.example.com/image/123.jpg` *are* "full" URLs. There may be a redirect from `example.com` to `www.example.com` which is happening when the page is loaded. What you'll need to check for is a "Location" header (or another type of redirect). – gen_Eric Oct 06 '15 at 21:04
  • i thought there is a better way than that but thanks. – Ori Price Oct 06 '15 at 21:05
  • 1
    I'm not sure if there is. If we use `google.com` as an example, both `google.com` and `www.google.com` have A and AAAA records, but if you try to access `http://google.com`, you get a 301 response and a redirect using a header of `Location: http://www.google.com/`. – gen_Eric Oct 06 '15 at 21:20

0 Answers0