We have uploaded our cms to a dedicated server. we have two options for our users (user your own domain, use subdomain). when a user register him/her self and select subdomain and want to access his/her website so he cant access it with his/her subdomain name integrated with our domain like (car.websaz.af) instead he can access it with the template name (choosed for his/her website) integrated with our domain name like (temp7.websaz.af). I have created a php file and used gethostbyname() to resolve the hostname to ip but not working.
cod used in the file is as below:
Subdomain 'tmp12.websaz.af' resolves to <?php echo gethostbyname('tmp12.websaz.af'); ?>

Could someone help me what the problem will be?

Thanks in advance

What type of server? Linux or Windows? Specifics would help.

Linux Server.
Cent OS 6.3

Member Avatar for LastMitch

@aryan200x

gethostbyname() not resolving hostname to ip

<?php echo gethostbyname('tmp12.websaz.af'); ?>

When you used a subdomain it should be in a name of the folder that has your website files.

So when you echo out from a subdomain it should be within the folder.

For example: The _name is the folder where you put your stuff.

This is how you should echo out from the subdomain:

<?php echo gethostbyname('tmp12.websaz.af/_name'); ?>

The file containing function gethostbyname is inside public_html and the folders for sub domains are inside websaz_server/HOST/website so I have changed the function as you advised:
<?php echo gethostbyname('tmp12.websaz.af/websaz_server/HOST/website/w12'); ?>
but still no luck for ip of that subdomain and it gives me tmp12.websaz.af/websaz_server/HOST/website/w12

Even if I write <?php echo gethostbyname('google.com'); ?> get google.com not showing its ip address.

Does it need any setting in the server?

I have put this file to test subdomain resolvation because in our cms when a user creates a website and saves it, when he clicks on his website in the dashboard to manage it, it opens in the browser with this URL tmp12.websaz.af not showing like property.websaz.af but if he type property.websaz.af in the browser then it comes.

Member Avatar for LastMitch

@aryan200x

Instead of gethostbyname() function

Try used gethostbyaddr() function.

You need to put property.websaz.af in a folder called property

When you type tmp12.websaz.af/property then it will open.

Regarding gethostbyaddr(), this gives the error 'Warning: gethostbyaddr() [function.gethostbyaddr]: Address is not a valid IPv4 or IPv6 address in /home/websaz/public_html/test.php on line 21.

This solution 'When you type tmp12.websaz.af/property then it will open.' did not work too.

If you know that some settings should be applied on the server then could you please write the instructions?

Thanks for helping

a subdomain usealy has the same ip as the main domain, which you know, it your server ip: $_SERVER['SERVER_ADDR']
or don't i understand what you want?

Yes a subdomain has the same ip as the main domain.
We have a CMS that users can create a website inside but when they go to their dashboard/My websites section and click on their website to change or add something to their website then their website opens in browser with a tmp+website id.maindomain.af like tmp12.websaz.af not like property.websaz.af but if they type property.websaz.af in the browser then it comes.
Someone said there is problem with gethostbyname() function that not working properly.

Member Avatar for LastMitch

@aryan200x

If you know that some settings should be applied on the server then could you please write the instructions?

I hope you know that you can't really get visitors actual real Ip address.

As far as I know there's no script that can do that.

You just want to find someone ip address? Right?

You don't need to used this gethostbyname() function anymore.

Read and try the code from this article (the code is a link):

http://www.webproworld.com/webmaster-forum/threads/97509-Getting-a-visitors-real-Ip-address

Just want to check hostname to ip address resolvation. Because when a user get registered in out cms and creates website then go to his dashboard and click on his website to manage it, it opens with a temporary url not the actual url like (property.websaz.af), it open with tmp12.websaz.af(this is a subdomain).
Subdomains are integrated with our main domain ip address which is not a new ip address and a visitor's ip address.
Someone advised that gethostbyname function is not working properly to resolve subdomains to your ip address.

Member Avatar for LastMitch

@aryan200x

Someone advised that gethostbyname function is not working properly to resolve subdomains to your ip address.

If that person advised you to use this function then did this person told you it should look like this:

gethostbyname('subdomain.domain');

If you still have issue please post your code. Right now I feel everyone is guessing including me.

It was because of /etc/host which was empty and now it is fixed by doing the settings in /etc/host.

Thanks for everyones help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.