iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old November 22nd, 2007, 12:54 PM   #1
Most Reputable Member
 

Join Date: May 2007
Location: UK
Age: 28
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice
[SOLVED] Getting the current domain

I want to assign a variable to the current domain of the web page. When I'm developing the site, the domain is "http://localhost/", but when I upload it the domain is "http://www.badmintonbible.com/".

So I'm using this variable to make links work both locally and on the site itself.

I've tried using $_SERVER['DOCUMENT_ROOT'], but this goes too deep: it returns all the server's file structure.

There must be a pre-assigned variable for this, but I haven't found it. Any ideas?
MikeHopley is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 22nd, 2007, 01:00 PM   #2
Highly Reputable Member
 

Join Date: Apr 2007
Location: Willich, Germany
Age: 21
Posts: 592
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough c010depunkk is a jewel in the rough
Re: Getting the current domain

I had the same problem and here's my solution. This function returns the current domain plus the folder structure to where the file is located plus a trailing slash:
Code:
function getLinkPrefix() {
    
preg_match('#^/([^/]+)/[.]*#',$_SERVER['PHP_SELF'],$regs);
    return 
'http://'.$_SERVER['HTTP_HOST'].'/'.($regs[1]==''?'':$regs[1].'/');

Hope this helps, you should be able to modify it to work. I think the $_SERVER['HTTP_HOST'] is interesting 4 u.

Last edited by c010depunkk; November 22nd, 2007 at 01:05 PM..
c010depunkk is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 22nd, 2007, 01:02 PM   #3
Elite Veteran
 

Join Date: Jan 2007
Location: You know where
Age: 32
Posts: 4,608
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 karinne is a name known to all karinne is a name known to all karinne is a name known to all karinne is a name known to all karinne is a name known to all karinne is a name known to all
Re: Getting the current domain

Hmmmm ... I can't test any of this as I don't have access but... have you tried

'HTTP_HOST'
karinne is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 22nd, 2007, 01:22 PM   #4
New Member
 

Join Date: Jan 2006
Location: Newport, UK
Age: 19
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 @lun is on a distinguished road
Re: Getting the current domain

what karinne said:

this has always worked for me

Code:
$url "http://".$_SERVER['HTTP_HOST']."/"
@lun is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 22nd, 2007, 01:40 PM   #5
Most Reputable Member
 

Join Date: May 2007
Location: UK
Age: 28
Posts: 1,107
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice MikeHopley is just really nice
Re: Getting the current domain

Quote:
Originally Posted by @lun View Post
what karinne said:

this has always worked for me

Code:
$url "http://".$_SERVER['HTTP_HOST']."/"
Fantastic, that's solved it -- and quickly, too.

Thanks everyone!
MikeHopley is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
highlight current page unitedcraig HTML, XHTML and CSS 53 February 13th, 2008 06:20 PM
[SOLVED] close current window in php script Posie PHP 7 December 14th, 2007 01:38 AM
[SOLVED] Domain Fowarding? Good Idea? TheSealPortalTeam HTML, XHTML and CSS 9 December 2nd, 2007 09:31 AM
Getting current URL in java QuikFrozen Other Languages 3 March 27th, 2007 07:38 PM


Search Engine Optimization by vBSEO 3.2.0 RC8