Part of the EllisLab Network
   
3 of 6
3
Automatic config[base_url]
Posted: 18 March 2008 12:54 PM   [ Ignore ]   [ # 21 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  02-14-2007

Rick beat me to the answer - I guess I need to work on my typing speed.

 Signature 

Trying to do it right the first time! whoops guess that didn’t work out so well…

Profile
 
 
Posted: 18 March 2008 01:49 PM   [ Ignore ]   [ # 22 ]  
Grad Student
Avatar
Rank
Total Posts:  88
Joined  03-09-2008

awesome, thanks for the tip.

Profile
 
 
Posted: 21 March 2008 01:19 PM   [ Ignore ]   [ # 23 ]  
Grad Student
Avatar
Rank
Total Posts:  88
Joined  03-09-2008
Code Arachn!d - 18 March 2008 12:53 PM

What I’ve done is checks on certain pages so that if the user goes to the page and it’s not https that it will redirect them to the https connection.

can this test just be

if(!$_SERVER['HTTPS']) {
//redirect to HTTPS
}

?

I’m not sure if that’s all encompassing or not (in other words, if that’s a good enough test for your suggestion above).
This is a “redundant” test as all links will be pointing to an HTTPS location, but have to make sure since people can type link locations manually.

Profile
 
 
Posted: 21 March 2008 02:33 PM   [ Ignore ]   [ # 24 ]  
Grad Student
Avatar
Rank
Total Posts:  88
Joined  03-09-2008

What I wrote above is what I did, but CI’s redirect function is only relative, so I had to use good old fashioned “header(‘location: mypate.com’);”

Profile
 
 
Posted: 09 April 2008 12:10 AM   [ Ignore ]   [ # 25 ]  
Grad Student
Rank
Total Posts:  48
Joined  11-25-2007

Sorry, But can someone help me to understand following code. I am not sure why we need to check $_SERVER[‘HTTPS’] == “on”?

(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
Profile
 
 
Posted: 09 April 2008 09:44 AM   [ Ignore ]   [ # 26 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

Quoting php.net:

Set to a non-empty value if the script was queried through the HTTPS protocol. Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol.

 Signature 
Profile
MSG
 
 
Posted: 22 April 2008 11:56 AM   [ Ignore ]   [ # 27 ]  
Summer Student
Avatar
Total Posts:  27
Joined  01-31-2008

So, adding the localhost condition turns into something like:

$proto = "http" .
    ((isset(
$_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
    
$_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$server .= '/'; // Added since the trailing slash was not present in the above code

// Add the current subdirectory on a local server
    
if (strstr($server, 'localhost'))
        
$server .= 'bh/';

Test in a subdirectory on dev, upload to production on any domain.

Not sure there would be a way to automatically detect a subdirectory when also eliminating the index.php?  And in theory you could setup a nice dev environment with .testdomain.com…

Profile
 
 
Posted: 23 April 2008 05:07 AM   [ Ignore ]   [ # 28 ]  
Summer Student
Total Posts:  26
Joined  02-19-2008

What if user use .htaccess to remove ‘index.php’ from url??

Profile
 
 
Posted: 23 April 2008 05:14 AM   [ Ignore ]   [ # 29 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  4839
Joined  07-14-2006

index.php is not a part of the base_url setting that is the index_page setting so if you add index.php to the base_url you are going to have trouble with certain methods and functions.

Profile
 
 
Posted: 23 April 2008 09:06 PM   [ Ignore ]   [ # 30 ]  
Summer Student
Total Posts:  26
Joined  02-19-2008

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’??

Profile
 
 
   
3 of 6
3
 
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 819, on March 11, 2010 11:15 AM
Total Registered Members: 120296 Total Logged-in Users: 49
Total Topics: 126414 Total Anonymous Users: 5
Total Replies: 664813 Total Guests: 448
Total Posts: 791227    
Members ( View Memberlist )