Jump to content

[SOLVED] I want $_SERVER['SERVER_NAME'] without the www.


cgm225

Recommended Posts

when I was using this function the last time it WAS without "www."  ;D

 

But if it isn't at your site, you can use "substr($_SERVER['SERVER_NAME'],4,strlen($_SERVER['SERVER_NAME']));"

 

syntax error because you forgot a " after "http://

$referer = "asdfasfd"; //what is your referer? ...could be "$_SERVER['Referer']"


if ($referer  == "http://" . $_SERVER['SERVER_NAME'] . "/login"){

}

(not tested)

 

kind regards :)

 

 

 

I wouldnt agree on using that code...

The reason your one may have come up like that vamos is because you were probably visiting the address http://website.com

 

Also the reason why that script id dodgy is imagine the website was website.com

the code would cut off four characters so it would look someting like...

http://ite.com  <-- notice first of characters webs have gone.

 

I would recommend...

 

$string="www.website.com";
$string= str_replace("www.", "", $string);

 

Problem is that the code might create a slash in the new string.

Try it out anyway

sure, you're right! But DON'T forget the dot in string to search for (www.) because you could geht a problem wenn a URL conaitns www somehow. Bad luck for you if some url ends with www like http://mywww.com .... so maybe you would like to combine both solutions like this:

 

 

$servername = "http://".$_SERVER['SERVER_NAME'];
// or $servername = "https://".$_SERVER['SERVER_NAME'];

if(strpos($servername, "www.") == 0 || strpos($servername, "www.") == 7 || strpos($servername, "www.") == { //0 = without "http"; 7=http; 8 =https; -depending on what you want.
    servername = str_replace("www.", "", $servername);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.