ERR CONNECTION REFUSED - why can't mobile find the absolute path of files through localhost?

I am developing a website with framework Bootstrap

During development, I came across the problem related to path of folders, images, pages and etc.

I was using include to include header and footer in my site, however, I always found an error in the path, either in The include header and footer, in the path of images and/or folders. That's when I started reading about Path relativo and absoluto.

For solving the header and footer path problem, I replaced my includes with file_get_contents, where I saved in the variable the absolute address of my site and then just complete with the necessary. In this case I can print the header and footer on any page of my site.

Example:

$a = file_get_contents("http://localhost/sites/nome_da_pasta/include/header.php");

echo $a;

To solve the problem of the path of images, folders and pages, I just inserted http://localhost/sites/nome_da_pasta/nome_do_arquivo.php inside the href of the a tag.

Before all these changes, I could access the site also through the mobile, typing in the chrome of the device:

IPv4/caminho_do_site/index.php

However, I had the problem of the relative path.

Until then the two methods mentioned above had solved my problem on the site using chrome browser on the notebook. However, when running the same site in mobile chrome or notebook mozila browser, errors appear:

  • a message appears on the phone ERR_CONNECTION_REFUSED
  • in mozila only opens the localhost.

Follows the print of the error on the mobile: insert the description of the image here

My doubts are:

  • is there a correct way to call the absolute path of images, folders, pages and even footers and headers (being includes)?
  • is there a better way to view the site on mobile? Without having to use IPv4 (even if the site is only on localhost)?
  • I do not understand how the same site, with the same settings and encodings runs in the chrome browser of the notebook, but has difficulty running through IPv4 on the mobile.
  • why can't "mobile" find the path of folders/files/images / pages in localhost if the site (in notebook) can?

Note: I would like to understand the questions I asked above, however, my biggest need is to be able to open the site on mobile as well.

Update:

I downloaded the mozilla browser on mobile to see if the problem was only in chrome, the funny thing is that the login page runs normally on mobile, however, when I type email and password, the error message appears, follow 2 prints of the test on mobile:

Login Screen: insert the description of the image here

After entering email and password on mobile (keep in mind that the website on the desktop all pages open normally):

insert the description of the image here

Author: Marcielli Oliveira, 2017-03-18

2 answers

First: do not use file_get_contents, or use include or require.

Relative and absolute paths are always based on what you defined when setting up your server. In Apache, you can set the path to DocumentRoot in apache2.conf. If you are using Xampp, find in c:\XAMPP\apache\conf\httpd.conf. Then change the guideline like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot C:/caminho/para/o/site
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory C:/caminho/para/o/site>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

Restart Apache. (source: https://stackoverflow.com/questions/10157333/xampp-change-document-root )

What you are doing here is changing the path that apache recognizes when you access port 80 of that machine. That is, localhost. Now, from what I saw in your question, you have set up multiple sites in one folder. The correct would be to create a VirtualHost for each site you have there, or put them on different ports, perhaps. In any case, it is already out of scope.

The problem you were having with include was because you were trying to use an absolute path that started before the folder of the site itself. So he was looking for header.php inside the root that is there in Apache, which probably contains the folder site.

 2
Author: Daniel, 2017-05-23 12:37:27

You need to go on PHP.ini and authorize include using HTTP.

Search php.ini for allow_url_include and if off Change to on, if 0 change to 1.

 1
Author: Will Knippelberg, 2017-03-27 13:55:11