CSS and JS does not load on mobile, via localhost

Asked

Viewed 686 times

0

Good morning! I’m making a small website, using Codeigniter 3 and Bootstrap 3.

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

Observing: I’m using the XAMPP.

What can it be?

*Example of CSS Call:

 <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. - Works normally.

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

  • 2

    Please increment your question with codes, CSS calls, so we can help you better

  • Question edited. I added code.

  • Dude, your base_url constant has to automatically pick up the url, not manually set

  • has a completion code down there, but you can use this also define('BASE_URL', $_SERVER['HTTP_HOST']); echo BASE_URL

  • Thanks for your help, but unfortunately it didn’t work out. Based on your answers, I found a satisfactory answer on the Internet, which solved my problem. Link: http://www.universidadecodeigniter.com.br/optimizando-a-configuracao-da-url-base-da-aplicacao/

  • $base_url = "http://" . $_SERVER['HTTP_HOST']; $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']); $config['base_url'] = $base_url;

Show 1 more comment

1 answer

1

use this to create the base_url or constant variable

<?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 seen, really has typo defect, the final code would be this above, the same can be seen working here at this link, it detects all parameters such as HTTP or HTTPS and also the subdir to create URL friendly

  • Thanks for your help, but unfortunately it didn’t work out. Based on your answers, I found a satisfactory answer on the Internet, which solved my problem. Link: http://www.universidadecodeigniter.com.br/optimizando-a-configuracao-da-url-base-da-aplicacao/

  • $base_url = "http://" . $_SERVER['HTTP_HOST']; $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']); $config['base_url'] = $base_url;

  • I’m glad you found the solution, but one studied in this solution above, is more robust, I’ve also used this one that you reported many years ago, I’ve been improving it until I got to this one that I sent you that is automatic collection from start to finish, URL friendly usage is the best solution

Browser other questions tagged

You are not signed in. Login or sign up in order to post.