ERR_CONNECTION_REFUSED - Why can not the mobile phone find the absolute path of files through localhost?

1

I'm developing a site with framework Bootstrap

During development, I came across the problem related to path (path) of folders, images, pages and so on.

I was using include to include header and footer on my site, however, I always encountered an error in the path, be it header and footer include, path of images and / or folders. It was then that I started reading about path relativo and absoluto .

To solve the header and footer path problem, I replace my includes with file_get_contents , where I save the absolute address of my site variable and then just complete it as 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 image, folder, and page path, I only inserted http://localhost/sites/nome_da_pasta/nome_do_arquivo.php into the href of the a tag.

Before these changes, I was able to access the site through the cell phone, typing in the chrome of the device:

IPv4/caminho_do_site/index.php

However, I had the relative path problem.

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 the mobile phone chrome or in the notebook's mozilla browser, errors appear:

  • A message appears on the phone ERR_CONNECTION_REFUSED
  • In Mozilla just open the localhost page.

Follow the error print on your phone:

Myquestionsare:

  • Isthereaproperwaytocalltheabsolutepathofimages,folders,pagesandevenfootersandheaders(beingincludes)?
  • Isthereabetterwaytoviewthesiteonmymobile?WithouthavingtouseIPv4(evenifthesiteisonlyonlocalhost)?
  • Idonotunderstandhowthesamesite,withthesamesettingsandencodingsrunsonthenotebook'schromebrowser,buthasdifficultyrunningthroughIPv4onthephone.
  • Whycannotthemobilephonefindthepathofthefolders/files/images/pagesonlocalhostifthesite(inthenotebook)can?
  

NOTE:IwouldliketounderstandthequestionsIaskedabove,butmybiggestneedistobeabletoopenthesiteonmymobilephoneaswell.

Update:

Idownloadedthemozillabrowseronmyphonetoseeiftheproblemwasjustinchrome,thefunnythingisthattheloginpageusuallyrunsonmyphone,butwhenItypeemailandpassword,theerrormessageappears,mobiletest:

Loginscreen:

Afterenteringemailandpasswordonmobile(keepinmindthatthewebsiteonthedesktopallpagesopennormally):

    
asked by anonymous 18.03.2017 / 04:50

2 answers

2

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

Relative and absolute paths are always based on what you set when configuring your server. In Apache, you can set the path to DocumentRoot in apache2.conf . If you're using Xampp, find it in c:\XAMPP\apache\conf\httpd.conf . Then, change the directive as follows:

<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: link )

What you're doing here is changing the path apache recognizes when you access port 80 of that machine. That is, the localhost. Now from what I saw in your question, you've set up multiple sites in the same folder. The correct one would be to create a VirtualHost for each site you have there, or put them on different ports, maybe. Anyway, it's 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 site's own folder. So he was looking for header.php within the root that is there in Apache, which probably contains the site folder.

    
27.03.2017 / 15:37
1

You must go to PHP.ini and authorize include using HTTP.

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

    
19.03.2017 / 03:50