shedokan Posted November 25, 2007 Share Posted November 25, 2007 Hello, Is there a way to check if a user entered www. before the url? thanks. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted November 25, 2007 Share Posted November 25, 2007 <?php if (strpos($_POST['string'],'www') { echo "Yes they did"; } else { echo "No they didn't"; } ?> Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 25, 2007 Author Share Posted November 25, 2007 doesn't works and you forgot to end the if condition with a ) twice. Quote Link to comment Share on other sites More sharing options...
trq Posted November 25, 2007 Share Posted November 25, 2007 <?php if (substr($_SERVER['SERVER_NAME'],0,3) == 'www') { echo 'www found'; } else { echo 'www not found'; } ?> Quote Link to comment Share on other sites More sharing options...
Orio Posted November 25, 2007 Share Posted November 25, 2007 A revised version... <?php if(strpos($_POST['string'], "www.") !== FALSE) { echo "Yes they did"; } else { echo "No they didn't"; } ?> EDIT- oh you mean in the url that they used to enter the page lol. In that case thrope is right. Orio. Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 25, 2007 Author Share Posted November 25, 2007 <?php if (substr($_SERVER['SERVER_NAME'],0,3) == 'www') { echo 'www found'; } else { echo 'www not found'; } ?> doesn't work I tried to echo $_SERVER['SERVER_NAME'] and one time I put the www and the other time I didn't and the result was the same both of the times and only echoed the url without www Quote Link to comment Share on other sites More sharing options...
trq Posted November 25, 2007 Share Posted November 25, 2007 Thats wierd. I use that exact same variable to determin which configuratiosn to load for my framework. eg dev.domainname.com loads my developement version stage.domainname.com loads the staging configuration. Never had a problem with it. Quote Link to comment Share on other sites More sharing options...
xyn Posted November 25, 2007 Share Posted November 25, 2007 Check you dont have http:// before the www. because without http:// substr($_SERVER[sERVER_NAME],0,3) will be "www" with http:// substr($_SERVER[sERVER_NAME],0,3) will be "htt" Quote Link to comment Share on other sites More sharing options...
trq Posted November 25, 2007 Share Posted November 25, 2007 No it wont. The http:// does not show up at in $_SERVER['SERVER_NAME']. It also much be in a valid request to the http server. Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 25, 2007 Author Share Posted November 25, 2007 ow and I forgot to mention that I'm using a sub-domain here's an online version of the script check you self and see that it doesn't work: http://neostar.110mb.com/test-www.php Quote Link to comment Share on other sites More sharing options...
trq Posted November 25, 2007 Share Posted November 25, 2007 So what exactly are you looking for? To see if your url starts with www, or contains www in the filename? You really need to descibe what you want better. A subdomain normally won't work with www on the front. Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 25, 2007 Author Share Posted November 25, 2007 I want that if the user goes to neostar.110mb.com so it will redirect him to www.neostar.110mb.com. Quote Link to comment Share on other sites More sharing options...
trq Posted November 25, 2007 Share Posted November 25, 2007 This would be best handled via mod_rewrite. I actually dought that www.neostar.110mb.com is a valid address for your site, simply because your entire site runs in a subdomain, but anyway. Try... RewriteEngine on RewriteCond %{HTTP_HOST} ^neostar.110mb.com [NC] RewriteRule ^(.*)$ http://www.neostar.110mb.com/$1 [L,R=301] in your .htaccess file. Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 25, 2007 Author Share Posted November 25, 2007 owww... ok I can't try your script yet because my webhost(110mb.com) doesn't support htaccess but they wll enable that feature so when they will I will test this script and post of phpfreaks forums any questions I will have. thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.