I don't know how to phrase this better, mainly because I dont really know how DNS fully works.
Given a URL and an IP, is it possible to tell PHP to make all requests to that IP AS the given URL instead of the real DNS (Just as if you edited your hosts file locally)?
The only solution I see is to run your own bind server, and tell your clients to use your bind server. You then have full control how a name is routed to a IP.
Unfortunately for your case, you are at the whims of your client.
If they type the IP address in their browser it will work, if they type the domain which has not been set up in DNS or in their hosts files, it will never reach a server that you control.
If you have designed you site correctly, it probably really shouldn't matter if they access it via domain name or IP address.
I think this is what apache does via .htacess or other configuration files. That is not a "change" to the DNS, but a way to manage every request as you want, even with a unique and generic .php file
Related
Is there a way to resolve DNS at server (using PHP), then include that pre-resolved IP address with domain name in html? So client's browser fetches directly from that IP without having a need to resolve DNS first?
Here is a bit more clarification. My PHP generated page has many external links to js, css and image files from different domains. It takes much time when DNS is resolved on clients' browsers. It can be done very fast on server but I don't want to links those resources directly from IP address. Instead I want something that tells browser that the domain example.com is hosted at 1.1.1.1 for example and no need to perform a DNS lookup.
Is it possible? or can there be a workaround?
Some thing like dns-prefetch with a value or attribute?
<link rel="dns-prefetch" href="http://example.com" value="1.1.1.1" />
Thanks in advance.
Well, you can resolve dns-name to IP.
While PHP can't do this, you can create a test file on your server. After that you fetch request for his file. According OSI model, DNS client will resolve DNS name->IP, after that you will have IP in your HTTP headers, because your real query depend on IP of server.
Low level. Windows and Linux both have an API for resolving DNS name -> IP. So you can use their functions in C++ to get IP without test file.
Or you can construct DNS message: DNS-message => UDP-datagram => IP-package. After you send it to DNS-server and wait for answer.
Your DNS-server IP you can find in your config.
I have a site say abc.com and a user account is accessed at abc.com/user. Now I want to add functionality that user can link his site say user.com to abc.com/user. Can u please give me an overview that how this process can be done dynamically via php?
Set up DNS to point the host name at the server
Set up the server configuration so the site is the default virtual host (so if an unrecognised domain name is used to request it, the right site will be loaded)
Use $_SERVER['HTTP_HOST'] instead of the path.
If I understood correctly - you want that a person who is entering user.com will see the content from abc.com/user.
I would recommend checking out launchrock.com they do exactly this, and it involves adding a CNAME dns record as I remember, another way to do this is to create a Proxy flag rule in httpd (mod_proxy must be enabled for this), so that you won't have to restart the server, you can always the .htaccess in your www dir.
doing so dynamically will be easy if you go the proxy route, as you just need to append a new proxypass every time a new site is deployed, or create a parameterized rule, like a regular htaccess, as far as automating DNS records creation, I'm sure that's possible and maybe DNS provider such as godaddy or AWS have api for those kinds of things, but more research is required.
How would this have to be created if possible? Can it only be created in cPanel, or is it possible to make a script for users to use without logging into cPanel that allows them to make their domain?
That should be possible depending on your hosting / server setup:
Add a wildcard domain CNAME record *.yourdomain.com;
Use a rewrite rule to direct all traffic to anything.yourdomain.com to a php script to handle the requests;
Do whatever you want in your php script: Use a header redirect, present another page in an iframe, etc.
A subdomain is just an entry in the DNS server configuration. Likely you'll be able to update the configuration by adding a bunch of lines in a file, or a new file altogether. This really depends on the DNS server software, maybe the one you use also has an API to be updated via a TCP socket.
Also if the target IP is shared (and thus you use name-based virtual host), or it's a different one, maybe you want an HTTP server listening on the port 80 on that IP.
Am sure there's answer on Google but I don't know how to formulate my question:
A php website is hosted on server like this: http://sub.realserver.com/website/index.php
Now I want to link the real domain name to it: http://therealwebsite.com
Problem is, when user visits:http://therealwebsite.com, he will see http://sub.realserver.com/website/index.php as he browse through other pages.
Question is how do I hide this realserver path and replace it with the domain name?
Thanks
edit: the website is hosted on a different server as the real domain name
I presume the domain name and the web site are pointing to the same server.
Although you could use URL rewriting (works with almost all popular web servers), the better solution is to set up your web server to provide that web site for the root of that domain name. How to do that completely depends on what server software you are using.
In apache, you need to create a so-called Virtual Host, configure it to respond to your domain name and set its DocumentRoot directive to the directory where your site is located.
See http://httpd.apache.org/docs/2.0/vhosts/examples.html for an example.
EDIT: I just read your comment. I'm afraid your options are rather limited. The easiest solution, but also the most dirty one, is to create one page with an IFRAME on it, that loads the site from the real server. You could also host a PHP proxy and on the server that hosts your domain name, and let it proxy the site on your
http://sourceforge.net/projects/php-proxy/
(I never used this, nor am I affiliated with this project, but it seems to claim to do what you want.)
I highly recommend though that you update your DNS records on your domain name so that it points to your server that hosts your site, and that you add a virtual host there.
you can do this with asp, there is a good resource on it here -
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
I'm planning to build a webapp where users can show off their data. I want our users to be able to show it off on their own site, just like cloudapp. You can set your own domain name, but still use the application's hosting service.
So my service is http://example.com/showoff but I want users to have the option to use http://showoff.example.net for their data.
I'm planning on doing it in PHP, but i'm open for suggestions if it comes to building this kind of service.
Let's assume your domain is "showoff.com" and their domain is "acme.com"
You have two basic options: "showoff.acme.com" or "acme.showoff.com". I have done this both ways.
For "showoff.acme.com":
The customer will need to set up a CNAME entry pointing to showoff.com in their DNS. Explaining to the customer how to do this is not trivial, and doesn't make much business sense unless you have a small, high-paying customer base.
You will need to configure an Apache virtualhost to answer all requests to all domains (not just showoff.com)
You cannot use SSL unless you configure a virtualhost and IP and certificate for each individual customer. (A pain!)
For "acme.showoff.com":
You will need a wildcard DNS record to point *.showoff.com to your server's IP (whether this is easy depends on your DNS provider); if you are unable to do this, you will need to create a DNS record for each customer.
You will need to configure an Apache virtualhost to answer all requests to *.showoff.com
You can use a wildcard SSL certificate for *.showoff.com
In both scenarios, in your PHP you can find out what domain was requested with $_SERVER['HTTP_HOST']. You will want to check this against your database of recognized domains, to determine which customer's data to show.
As you can see, most of the work is in DNS and Apache; it doesn't really matter whether you use PHP or some other language.
They have to point a DNS entry for showoff.usersite.com to your server. You can read that from the $_SERVER variables and off you go! Point another domain to your site and try: print_R($_SERVER) and you will see the domainname pointing to you.