I will try to answer your two questions thoroughly...
a) "Is there a way test sites using ip without using /~rootuser/ after the ip[?]"
Independantly of GoDaddy, of course you can. The server (e.g., Apache) has to be configured to serve that website for that IP address. However, logically, you won't be able to serve more than one website per IP that way. That is not practical and that is one reason you'll want to use multiple names that map to that IP).
As for GoDaddy, it all depends what kind of package you "bought" and what it allows you to do. If you have a dedicated IP, maybe you can ask it to serve a particular website for that IP, but chance are you bought a shared hosting plan and therefore the same IP is used for multiple users / clients / sites. So they won't default that IP to your website. So I would suggest that you rely on a name in practice. The name will usually be a domain name you register, like EXAMPLE.COM.
Technically, if you had the control of the machine configuration (chance are not on GoDaddy, especially if you bought a shared hosting plan), you can even tell the machine to serve your website for "anynameyouchoose" and locally (i.e., on your own computer), you can make sure that it maps "anynameyouchoose" to the target host IP XXX.XX.XX.XX. In Linux and Windows, there is an hosts file where you can specify a mapping between a name and an IP. You can even decide to resolve Microsoft.com to XXX.XX.XX.XX if you want and if the machine located at XXX.XX.XX.XX is configured to serve a specific content for Microsoft.com, it will!
In practice, there is public name servers that map domain like Microsoft.com to the registered IP, but it is good to know how it works, and it might come handy when you want to fool a friends on April 1st. ;-)
That is a bit advanced, but if you understand what I just said, you may also try to associate any made up domain name in your host control panel to your site content and then map that name to the IP of the machine where your site is. It might work, but it all depends what GoDaddy or any host you'll use allow you to do.
I think GoDaddy currently offer a free domain registration with your hosting plan or you can at least buy one (I'm sure you plan to buy one or more anyway). Some host (I do not know for GoDaddy) also offer their users some generic sub-domains (your-site-name.godaddy.com -- where GoDaddy.com can be anything the host use as their base domain for their users). That could also give you a root host name, without the need to deal with a deep root path.
You can also buy only one domain name and create lot of subdomains to map to each of your sites if you have multiple sites. Like if you buy EXAMPLE.COM, you can then create SITE1.EXAMPLE.COM, SITE2.EXAMPLE.COM, etc.
That is all if you absolutely want to avoid to deal with a variable root path in your code.
b) "[...] or let php get XXX.XX.XX.XX/~rootuser/site as server name[?]"
If you want to do this, in PHP, you might want to set some configuration variables to hold your host (IP or name) and your root path (e.g., /~rootuser/site). So even if you run your site at multiple hosts with different constraints, you limit the amount of code you have to change to the configuration variables. You can try to overwrite the $_SERVER['SERVER_NAME'] value, but I would advice against doing it that way, because that is not the purpose of this special variable and that will create more problems down the road.
There are other parts of the URL that can change depending of the host like the protocol (http or https) and the port number. If you find out you have to repeat yourself too much in your code, create yourself variables or functions you can re-use.
If you want to manage this automatically, you will want to look into these indices of $_SERVER super global:
- HTTP_HOST : this will give you the host IP or name as typed in the address bar of the browser.
- REQUEST_URI : this will give you everything after the HOSTNAME (path + query string)
So for the address http://www.example.com/~root/site1/sub-directory/page?var1=abc&var2=def the values will be:
- $_SERVER['HTTP_HOST'] => www.example.com
- $_SERVER['REQUEST_URI'] => /~root/site1/sub-directory/page?var1=abc&var2=def
You can read about what is usually available in $_SERVER there: http://php.net/reserved.variables.server
Take note that some variables in $_SERVER might be only available for some server (Apache, IIS, etc.) But do not worry much about this for now. Most people tend to use Apache with PHP and the common server variables you will want to use should be available in all popular servers.
Of course if you use a sub-directory as in my example, you won't be able to easily figure out what is your "root path" (i.e., /~root/site1). So you'll have no choice than to manually configure it for each setup.
I also encourage you to take advantage of function phpinfo(). Create a page named info.php with this code:
<?php
phpinfo();
When you will visit that page, you will see everything that is available in $_SERVER, along with lot of other useful info. For example if you visit http://hostname/the/path/to/info.php?var1=abc&var2=def -- You will see in which variables the query string "var1=abc&var2=def" is included.
You may want to create a default configuration file (config.php) that optionally include a file that serve to "overwrite" the default value if needed (config.env.php):
config.php can be:
<?php
$config['host'] = $_SERVER['HTTP_HOST'];
$config['path'] = '/';
if (file_exists('config.env.php')) {
require('config.env.php');
}
?>
config.env.php on your GoDaddy account can then be:
<?php
$config['path'] = '/rootuser/site1';
?>
This config.env.php file will be the one that change from your multiple setups of the same site. For example you can have a "development" version locally, a "test"/"staging" version online and a "production" version online. Each of those environment can have their own specific configuration.
You will then want to include config.php in all your pages so the configuration variables are available.
Also, in your pages, you can build all your internal links (link inside the same site) without specifying the protocol, host and port. Those links will therefore be "relative to the host". So if you link to "/~rootuser/site/sub-directory/page-name", you won't need to specify the "http://host:port", it will use the actual one. Why repeat yourself, add more characters, etc. when you don't have to? ;-)
I would also suggest that you always use absolute path (i.e., starting with /) for all your internal links instead of be tempted to put relative path. For example, use "/section-x/sub-y/page-z" instead of using "sub-y/page-z" in your page located at "http://host/section-x/index"). That will usually create yourself less headache to manage, unless you really have a good reason and know what you do.
Of course, if you can eliminate the need to have a variable root path in all your environments, that will simplify your code base.
I also want to mention that there exist an HTML tag that allow you to define the base path for all the links in a webpage. However, you will have to understand correctly how it works. I suggest you go check this if you are curious about it: Is it recommended to use the <base> html tag? -- this is not what I would recommend you to do, but it is good to know it exists.
You should also set yourself a local development environment if not already done (WAMP or LAMP packages can help you get a quick start; look for WampServer if you are on Windows).
I hope that is clear and that this make you understand the whole thing a bit better. Otherwise, feel free to ask questions so I can improve my answer.