view raw
Zaky Muhammad Zaky Muhammad - 8 months ago 39
PHP Question

<?php echo base_url();?> and <?php base_url();?>

<script src='<?php base_url();?>assets/js/jquery.min.js'></script>

the script above is code that my friend use, that works just for him, but if i change it to
<?php echo base_url();?>
and it's work for me, not for him.
It's become a problem when we transfer files each other, What i am supposed to do ?
thank you.

I've solution script for my case, change this from config.php :
$http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
$urlbaru = str_replace("index.php","", $_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$http" . $_SERVER['SERVER_NAME'] . "" . $urlbaru;


Please show more about your problem detail like paste your error code in here that we could use those information to help you.

Btw, base_url() isn't a php embedded function, one of the potential problem is that your friend custom a function named base_url() that supposed to return it's root path. So, you have to either include or build the same function with the same name to your script.


function base_url()
  return dirname($_SERVER['SCRIPT_FILENAME']);

And the 'src' inside your tag should point to your jQuery source file.