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 Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624460 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. Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624474 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 Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624476 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? Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624478 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.... Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624480 Share on other sites More sharing options...
redarrow Posted August 24, 2008 Share Posted August 24, 2008 colddude told you already........ Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624482 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. Link to comment https://forums.phpfreaks.com/topic/121133-is-there-any-php-function-that-can-get-the-domain-prefix-user-has-typed/#findComment-624485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.