Part of the EllisLab Network
   
4 of 4
4
Automatic config[base_url]
Posted: 23 April 2008 09:21 PM   [ Ignore ]   [ # 31 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  04-23-2007
Adods - 23 April 2008 09:06 PM

Yes, but if user call url like: http://www.domain.com/controller/method

will this script return ‘http://www.domain.com’ or ‘http://www.domain.com/controller/method’??

only http://www.domain.com/, but if your application is in a subfolder, then http://www.domain.com/subfolder/

 Signature 

A Better and more Flexible Paging Solution for CI
Automatic config[base_url]

Profile
 
 
Posted: 23 April 2008 10:00 PM   [ Ignore ]   [ # 32 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  660
Joined  06-07-2007

I would just like to say that I use this with CodeExtinguisher and haven’t had problems with myself or anyone using codeextinguisher

 Signature 

CodeExtinguisher
Download: codex2_rc14.2.zip - 219 KiloBytes of Gloriousness!
Demo: Public preview - login with preview:preview
Temporary Docs: PBWiki

Profile
 
 
Posted: 24 April 2008 12:09 PM   [ Ignore ]   [ # 33 ]  
Summer Student
Avatar
Total Posts:  8
Joined  01-31-2008

I neglected to add the last line in the code, though it could probably be pieced together from the previous posts:

$proto = "http" .
    ((isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
    
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= '/';

    if (
strstr($server, 'localhost'))
        
$server .= 'subdirectory/';
        
$config['base_url']    = $proto . $server;

As already said, this would return only the base http://www.domain.com/ or http://www.domain.com/subdirectory/ depending on what you specify for “$server .= ‘subdirectory/’ when testing on localhost.

The main advantage we’ve got now is the handling of http/https, you’ll still need to update your subdirectory for each project’s config.php file…

Profile
 
 
Posted: 24 April 2008 02:19 PM   [ Ignore ]   [ # 34 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  04-23-2007
bhogg - 24 April 2008 12:09 PM

I neglected to add the last line in the code, though it could probably be pieced together from the previous posts:

$proto = "http" .
    ((isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
    
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= '/';

    if (
strstr($server, 'localhost'))
        
$server .= 'subdirectory/';
        
$config['base_url']    = $proto . $server;


As already said, this would return only the base http://www.domain.com/ or http://www.domain.com/subdirectory/ depending on what you specify for “$server .= ‘subdirectory/’ when testing on localhost.

The main advantage we’ve got now is the handling of http/https, you’ll still need to update your subdirectory for each project’s config.php file…

But my original contribution already handles subdirectory, maybe you can just combine the two, where you handle the protocol.

$proto = "http" .
    ((isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
    
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

 Signature 

A Better and more Flexible Paging Solution for CI
Automatic config[base_url]

Profile
 
 
Posted: 24 April 2008 11:50 PM   [ Ignore ]   [ # 35 ]  
Summer Student
Avatar
Total Posts:  8
Joined  01-31-2008

We’ll need to tweak it a bit more… doesn’t basename() return the final portion of the URL?  So with someone accessing a page such as:

http://localhost/subdirectory/controllername/function/parm1/parm2

It would return something like “http://localhost/subdirectory/controllername/function/parm1” with the last piece removed.  We could use a simple search for the first / after the root URL to get the subdirectory, if we limit it to one level deep.  But what about when it’s launched to http://www.domain.com? Wouldn’t it then interpret the controllername as the subdirectory instead?

Brian

Profile
 
 
Posted: 25 April 2008 01:53 AM   [ Ignore ]   [ # 36 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  164
Joined  04-23-2007
bhogg - 24 April 2008 11:50 PM

We’ll need to tweak it a bit more… doesn’t basename() return the final portion of the URL?  So with someone accessing a page such as:

http://localhost/subdirectory/controllername/function/parm1/parm2

It would return something like “http://localhost/subdirectory/controllername/function/parm1” with the last piece removed.  We could use a simple search for the first / after the root URL to get the subdirectory, if we limit it to one level deep.  But what about when it’s launched to http://www.domain.com? Wouldn’t it then interpret the controllername as the subdirectory instead?

Brian

Nope. That’s why we are getting the scriptname, because we are only looking at the location of index.php only, and not actually processing the whole url. Why don’t you try it first so you’ll know.

I’ve tested this approach even if the application is in a sub/sub/subfolder, it wouldn’t matter.

 Signature 

A Better and more Flexible Paging Solution for CI
Automatic config[base_url]

Profile
 
 
Posted: 25 April 2008 09:21 PM   [ Ignore ]   [ # 37 ]  
Summer Student
Avatar
Total Posts:  8
Joined  01-31-2008

I did try it first and it was cutting off the subdirectory, likely since I’m not using index.php (mod rewrite)…

Profile
 
 
Posted: 02 May 2008 11:26 AM   [ Ignore ]   [ # 38 ]  
Summer Student
Avatar
Total Posts:  8
Joined  01-31-2008

My apologies, I had an extra $server .= “/”; in there from a previous version of the code, your code works just fine!

Profile
 
 
Posted: 04 May 2008 03:36 AM   [ Ignore ]   [ # 39 ]  
Summer Student
Total Posts:  12
Joined  05-01-2008

Thanks for this. I will probably change servers a few times so this is always handy raspberry

Profile
 
 
Posted: 08 August 2008 01:07 PM   [ Ignore ]   [ # 40 ]  
Summer Student
Total Posts:  1
Joined  08-08-2008

This is what I use:

$config['base_url'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') . '/';

Why do you need to include the domain? If you just use a relative (relative server?) path, you don’t need to worry about the domain or the protocol.

Profile
 
 
   
4 of 4
4
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61059 Total Logged-in Users: 22
Total Topics: 73867 Total Anonymous Users: 1
Total Replies: 398465 Total Guests: 345
Total Posts: 472332    
Members ( View Memberlist )
Newest Members:  bnolenstanjadebieSan2kakifemreSchottec2kmeenazterjinFuadgeorge_k_allis