kee2ka4 Posted August 24, 2008 Share Posted August 24, 2008 Hi everyone, I use the following redirect_to($address) function that I use to redirect a user to a page based on the parameter passed. Here is the code: define('WEBSITE', 'http://domain.com/'); function redirect_to($address) { header('location:'.WEBSITE.$address); exit; } I have a another domain name called http://domain.co.uk/ and hence if a user has come to the site using domain.co.uk then I do not want it to change to domain.com. But whenever the redirect_to function runs it loads http://domain.com since I have definted that in the 'WEBSITE' variable. Is there any function in php that can get the main domain name that the user has typed in the URL. I only need the main domain, no subfolders, so i.e. http://domain.co.uk or http://domain.com, whatever the user has typed in the URL when they visited the site. Thanks Ket Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 24, 2008 Share Posted August 24, 2008 you can store it in a session example <?php if(empty($_SESSION['domain'])){ $_SESSION['domain'] = "Blah"; } #then in the page use $_SESSION domain for all your links ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 24, 2008 Share Posted August 24, 2008 sessions start with <?php session_start(); //more code as advised below// ?> remeber every page got to use session all need the session_start(); on the top line off the php code. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 24, 2008 Share Posted August 24, 2008 sessions start with <?php session_start(); //more code as advised below// ?> Yes I forgot it but however sessions do not always need that if session autostart is turned to on Quote Link to comment Share on other sites More sharing options...
kee2ka4 Posted August 24, 2008 Author Share Posted August 24, 2008 Hi, thanks for your msg. Um I didn't quite get that. How can I store the URL that the user has typed in a $_SESSION? Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 24, 2008 Share Posted August 24, 2008 you should always type the session_start() it good code pratice with any programming lanuage...... half mesures dont get jobs lol.... Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 24, 2008 Share Posted August 24, 2008 colddude told you already........ Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 24, 2008 Share Posted August 24, 2008 you should always type the session_start() it good code pratice with any programming lanuage...... half mesures dont get jobs lol.... Actually if you are using session autostart than putting in session_start() will cause some funky urls occasional and is doing something unneeded so its would be bad programing practice good practice would be knowing your servers config's and using the language to that config you want. 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.