Jump to content

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


cgm225

Recommended Posts

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
Share on other sites

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 :)

 

 

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.