1
I’m developing a website with framework Bootstrap
During development, I came across the problem related to path (path) of folders, images, pages and etc.
I was using include
to include the header
and the footer
on my site, however, I always found an error on the way, either in header and footer include, in the path of images and/or folders. It was then that I began to read about way relativo
and absoluto
.
To solve the header and footer path problem, I replaced my includes with file_get_contents
, where I save in the variable the absolute address of my website and then only 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, just insert http://localhost/sites/nome_da_pasta/nome_do_arquivo.php
within the href
tag a
.
Before all these changes, I was able to access the site also through mobile, typing in the device Chrome:
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 on mobile phone’s Chrome or in the notebook’s mozila browser, errors appear:
- On the mobile appears a message
ERR_CONNECTION_REFUSED
- In mozila only opens the localhost page.
Follow the error print on cell phone:
My doubts are:
- There is 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? No need 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 notebook Chrome browser, but has difficulty running through Ipv4 on mobile.
- Why "mobile" cannot find the path of folders/files/images/pages on the localhost if the site (on the 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 also.
Updating:
I downloaded the browser Mozilla 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, error message appears, follow 2 prints of the test on mobile:
After entering email and password on mobile (keep in mind that the website on desktop all pages open normally):
in place of
localhost
Voce has to use the IP of the 'server' machine, where your webserver is running in the paths– andrepaulo
Isn’t it Ipv4? I’m a little lost in this area. I’m running locally, so before I could see through Ipv4.
– Marcielli Oliveira
Have you ever tried to do the
include
and use the images starting the path by the backslash\
? This way, the URL will be related to root of the application. For exampleinclude("/sites/silotransce/header.php")
. You can also set up for the root be the folder itself silotransce, just to doinclude("/header.php")
, which facilitates the deploy of the application.– Woss
I’ll try it this way, Anderson. So you think that if I do it this way, I can run on the phone too? Is it "file_get_contents" that is giving problem?
– Marcielli Oliveira
I tried and it didn’t work, but I think I figured out the problem and I’m not sure how to fix it. It is noticed that in the link that I am using as absolute path, has the localhost. And in cellular what is used to open is the number of Ipv4. So much so that the login screen normally opens pq in the path still ta the IP, but qnd enters the home page becomes localhost and then gives the connection error. Does anyone know how to put a default IP in place of the localhost on the href link?
– Marcielli Oliveira
Do not use
file_get_contents
for this purpose, useinclude
orrequire
. Using my tip above will solve your problem. If it didn’t work, you must have done something wrong. Post your folder structure and code, please. So we can help you better.– Woss
Hello, is it really necessary that the
include
be done using only absolute paths ? After all, if it is one framework, you can easily access the folderassets
orimagens
or even any other file on the server without the need to use absolute paths, using only relative paths to possesspaths
customized, there is here information about the types of paths and some examples, although it is almost a summary.– Edilson
Thank you, after analyzing the information you gave me, I did as Anderson had said before, but in my case it was not necessary to use the "/" bar before the name.php. Edilson, then I realized it really wasn’t necessary.
– Marcielli Oliveira
Right, create an answer with the solution used. If you solved your problem using
barra
, remember that you can always use theDEFINE('DS', DIRECTORY_SEPARATOR)
, and when you need to write a bar, just typeDS
, and you won’t have to guess if it’s / or . However I recommend creating make use ofpaths
customized.– Edilson