Welcome Guest, Not a member yet? Register   Sign In
2 Baseurl
#1

HI , it's possible to set base_url depends on $_SERVER  variable ?
Reply
#2

Yes, as CodeIgniter are just plain PHP you can access it everywhere. Just modify your /app/Config/App.php and you are gold. Depending on where that setting comes from, you may need to validate it first.
Reply
#3

(This post was last modified: 08-23-2020, 01:44 AM by pippuccio76.)

(08-22-2020, 12:00 AM)jreklund Wrote: Yes, as CodeIgniter are just plain PHP you can access it everywhere. Just modify your /app/Config/App.php and you are gold. Depending on where that setting comes from, you may need to validate it first.

But it's a variable in a class , i cannot use if statement :


Code:
    if ($_SERVER['SERVER_NAME']== 'http://localhost:8080/') {
        public $baseURL = 'http://localhost:8080/';

    }else{
        
        public $baseURL = 'https://mywebsite.com/';
    }
Reply
#4

(This post was last modified: 08-23-2020, 01:55 AM by jreklund.)

You can always put it in the __construct or you can modify your /public/index.php to handle all your "Environment variables" set by Apache/Nginx, and define it (just as we do with FCPATH). And use the defined name in /app/Config/App.php.

With the example given, it's just better to have two different .env files, if you just need different live and development settings.
Reply
#5

Thank's work fine , can i do the same for db ? but migrate don't work because $_SERVER['SERVER_NAME'] isn't isset
Reply
#6

Yes, I'm doing it for multiple values. Never used migrate thought, but just set a default value in case it's not set.

Don't use SERVER_NAME as is, you need to add some form of validation, make an array of acceptable values for security.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB