dzhax Posted October 5, 2008 Share Posted October 5, 2008 hello. i use no-ip.org for my domain name. i was wondering if there is a php script to do something likeif url in address bar is mail.mydomain.com then redirect to mail.htmlif url in address bar is forum.mydomain.com then redirect to forum.htmletc...thanks in advance for any help on this topic. i am new to php so any help would be great. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 5, 2008 Share Posted October 5, 2008 See $_SERVER['SERVER_NAME'] (use Ctrl+F to find 'SERVER_NAME') and switch. switch($_SERVER['SERVER_NAME']){ case 'mail.example.com': //... break; case 'forum.example.com': //... break; default: //neither} Link to comment Share on other sites More sharing options...
dzhax Posted October 6, 2008 Author Share Posted October 6, 2008 thank you for the reply. as i said before i am new to php. where would i put this switch statement? it would need called when the page loads. Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 6, 2008 Share Posted October 6, 2008 It must be at the top of your PHP, before anything, including whitespace, is output. That's because you'll need to use the header function, which sets an HTTP header to be sent. HTTP headers must be the first things sent to the browser. Link to comment Share on other sites More sharing options...
dzhax Posted October 7, 2008 Author Share Posted October 7, 2008 i just read the page about the header function. made no sense of it. could you please post an example of a full working .php with this in it. it can be plain. like no text or anything. it just checks the url and then i can add the redirect in after. so maybe ill understand? Link to comment Share on other sites More sharing options...
Jesdisciple Posted October 7, 2008 Share Posted October 7, 2008 i just read the page about the header function. made no sense of it. could you please post an example of a full working .php with this in it. it can be plain. like no text or anything. it just checks the url and then i can add the redirect in after. so maybe ill understand?You won't understand what it is until reading the standard, which is about as bad as a legal document. (I use exit instead of break here because there's no need to keep thinking when the user won't be using the rest of the page.)<?phpswitch($_SERVER['SERVER_NAME']){ case 'mail.example.com': header('Location:/mail'); // redirects to mail.example.com/mail exit; case 'forum.example.com': header('Location:/forum'); // redirects to forum.example.com/forum exit; default: // The user somehow found a subdomain you didn't know you had. :\}?> Link to comment Share on other sites More sharing options...
dzhax Posted October 8, 2008 Author Share Posted October 8, 2008 thanks man your the best. it works! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.