CSS and JS does not load on mobile, via localhost

0

Good morning! I'm doing a small site using Codeigniter 3 and Bootstrap 3 .

On PC, CSS and JS work perfectly well, but when I try to access it through the Smartphone , by localhost, it loads only HTML.

Note : I'm using XAMPP.

What can it be?

* CSS Call Example:

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

* Example of JS call:

 <script src="<?php echo base_url('assets/js/site.js'); ?>"></script>

* Base URL is configured this way:

 $config['base_url'] = 'http://localhost/teste';

* On the PC, type the URL: localhost / test. - It works normally.

* On the smartphone I type the IP address instead of "localhost": eg: 192.168.x.x / test . - Does not load CSS, nor JS. Only HTML.

    
asked by anonymous 19.05.2017 / 16:25

1 answer

1

Use this to create the base_url variable or constant

<?php
    define('siteprot', $_SERVER['HTTPS'] ? 'https://' : 'http://');
    define('sitehost', $_SERVER['HTTP_HOST']);
    define('siteuri',  $_SERVER['REQUEST_URI']);
    define('siteindex', '/'.max(explode('/', dirname($_SERVER['PHP_SELF']))).'/');
    define('siteurl', siteprot . sitehost . siteindex);
?>

<li>
    <?php echo siteurl; ?>
</li>
<li>
    <?php echo siteprot; ?>
</li>
<li>
    <?php echo sitehost; ?>
</li>
<li>
    <?php echo siteuri; ?>
</li>
<li>
    <?php echo siteindex; ?>
</li>

Sorry, the code posted was a beta, just now I saw, it really has a typo, the final code would be this one, the same can be seen working here in this link , it detects all parameters like HTTP or HTTPS and also the subdir to be able to create friendly url

    
19.05.2017 / 18:39