cgm225 Posted May 31, 2008 Share Posted May 31, 2008 Is there a way to echo the server without the preceding www. ? Restated, I basically want to: <?php echo $_SERVER['SERVER_NAME'] ?> but without the www. Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/ Share on other sites More sharing options...
cgm225 Posted May 31, 2008 Author Share Posted May 31, 2008 Then, also, how would I make an if statement to read something like this if (($referrer == "http:// . $_SERVER['SERVER_NAME'] . "/login") Right now I am getting syntax errors.. Thank you all in advance! Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/#findComment-554260 Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 when I was using this function the last time it WAS without "www." 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 Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/#findComment-554261 Share on other sites More sharing options...
cgm225 Posted May 31, 2008 Author Share Posted May 31, 2008 Thanks again! Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/#findComment-554266 Share on other sites More sharing options...
ILYAS415 Posted May 31, 2008 Share Posted May 31, 2008 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 Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/#findComment-554268 Share on other sites More sharing options...
kbh43dz_u Posted May 31, 2008 Share Posted May 31, 2008 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); } Link to comment https://forums.phpfreaks.com/topic/108136-solved-i-want-_serverserver_name-without-the-www/#findComment-554272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.