Ukasha
Ukasha

Reputation: 2334

What is better? Using 'base_url()' or './'?

I have been using CodeIgniter Framework for some months.

In views, I usually include external css and js with base_url(), just like this:

<link href="<?php echo base_url() ?>assets/css/custom.css" rel="stylesheet">

But someone tells me that using ./ also works too. And that's true.

So, what is better ( in security )?

Upvotes: 3

Views: 181

Answers (4)

winnie damayo
winnie damayo

Reputation: 426

You can used either, but its a good practice in Codeigniter to use base_url().

Upvotes: 2

Tanseer UL Hassan
Tanseer UL Hassan

Reputation: 156

you can use use ./ instead of base_url(). ./ is the root directory of your codeIgniter installation and it will get that bath in most cases that are same as base_url(), but base_url() is best practice to use because in some server ./ does not work or some other issue.

Upvotes: 1

JMS786
JMS786

Reputation: 1109

base_url() is just a helper (URL helper in CI). Some people just find it easier to use, so I don't see any added security by using base_url().

In case of ease of use, I see so many people use it like

<?php echo base_url()."controller/function";?>

while actually you can use it like

<?php echo base_url("controller/function");?>

Upvotes: 2

Timps
Timps

Reputation: 58

base_url() is a better choice to use. There isn't a cost difference using a relative or complete url, and this way you know it will point to the right spot.

It's a better habit to be in, and you can pass URL parameters to it and keep code neat.

Upvotes: 3

Related Questions