PHP İle Domain Adını Alma - Get Domain Name With PHP

bildiğiniz üzere php de $_SERVER['HTTP_HOST'] değişkeni bir sitenin domain adını veriyor.
tabi siteye www.site.com olarak bağlanmışsanız www.domainadi.com, http:// olarak bağlanmışsanız (ww koymadan) sadece domainadi.com
domain adını okutup email olarak göndermem gerekiyordu bir kod yazarken, bunu da şu şekilde sağladım. umarım işinize yarar :)

as you know, the variable $_SERVER['HTTP_HOST'] shows website’s domain name
but if you log in to website as www.website.com , its output will be www.website.com, but if you log in as only http:// (without www) , it’s output will be website.com
i needed to get the domainname and send as email at one php code, so i coded these tiny script which always gives only the domain name

1
2
3
4
5
6
7
//domain adı alma kodu - www.soulsmasher.net
if (substr($_SERVER['HTTP_HOST'], 0, 4) == "www.") {
$domainadi = substr($_SERVER['HTTP_HOST'], 4);
} else {
$domainadi = $_SERVER['HTTP_HOST'];
}
echo $domainadi; // illa ki domain adını gösterir

düzenleme: $_SERVER['SERVER_NAME'] diye bu işi gören kod varmış :)
enjoy ;)

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

0 Responses to “PHP İle Domain Adını Alma - Get Domain Name With PHP”


  1. No Comments

Leave a Reply

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 5 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a