I just moved my site to my local computer(a mac) but the site is not able to load properly because the include files doesn't seem to be able to include properly.
say eg:
I have the following lines:
include($_SERVER['DOCUMENT_ROOT'].'/pages/includes/functions.php');
on my index.php but the files are not able to be included properly.
I tried to use the functions in the file but it doesn't seem to be able to run the functions properly as per online.
I tried echo-ing $_SERVER['DOCUMENT_ROOT'] but it shows: /Applications/MAMP/htdocs
I'm not sure if that is the full path or if there is anything else i need to add to the url to get my files to be properly included. Perhaps i'm missing something. Any help will be greatly appreciated.
Related
I try to include a php file from the same server but a different domain within a php site (domain.com).
include 'domain2.com/file.php';
the file should look like this for example:
echo 'test';
I now want the main site to have the file.php included to echo 'test' on the site.
However, it doesn't.
Does anybody have an idea how I could solve that?
My thoughts are the following, though I cannot solve it myself. Maybe they help you to come up with a solution:
It seems like it is included but the file.php does not return anything, because the php is being run on 'the other domain's server'. So the echo could be done in the other file, but is not included within the main site.
Note that if I include via path, it works:
include '../domain2/file.php';
Note also that allow_url_include and allow_url_fopen are allowed in the php.ini.
So I have an issue with wordpress php includes after I've made an app via cordova for iOS. Basically, the code I have on the live website right now is:
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-includes/wp-db.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-includes/class-phpass.php');
However this only works live. When I make the app, $_SERVER['DOCUMENT_ROOT'] does not return the correct path to include the file I need. What path can I use to make sure these wordpress files are included in my external php file?
Thanks!
I found out that the answer to this was to echo $_SERVER['DOCUMENT_ROOT'] in a test php file and it came back with my root path, this allowed me to change it accordingly and it then worked remotely and not just locally.
Thanks for the help!
When I echo "PHP_SELF" in localhost running on xampp, I get the project folder as the echoed text e.g.
// index.php
<?php echo $_SERVER["PHP_SELF"]; ?>
The answer is
/a3-ver-9.0/index.php
but if I was on a server with a domain, that line would just return "/index.php"
Is there any way I can temporarily changes the default root in xampp to reflect this?
The reason is because I use absolute paths from root to include resources e.g. images.
however these absolute paths will not work if the root is not set correctly!
Cheers
EDIT
To make things more clear...
I have a website with php files that return parts of the page e.g. header.php and footer.php etc.
I have an installation of wordpress and in the wordpress template, I include these files. and because im including these files from different directories, the paths inside the included files must be absolute.
however the files in the header.php are included like:
<img src="/images/image1.jpg" />
now this include is correct, and when I've finished the project and upload it to my server it will correctly retrieve the image.
but when working with localhost, the root folder "/" is the folder where ALL my local projects are kept.
So i need a way to temporarily change the localhost root for each project, so i dont have to mess about changing a load of paths when the project is ready for upload!
Hope this made more sense
However when working on local host
Best way to solve this is using virtual hosts for your projects locally.
So something like www.project.local actually shows your project.
Here is a tutorial how to achieve this in xampp.
Okay, now I see what you mean, here you go this will help you, just change the root to the folder of your current project, for example:
"C:/xampp/xampp/htdocs/a3-ver-9.0/"
Greetings ! I have a project that has php index.php file in /htdocs. Also include files like dboperaitons.php, config.php and css file also in /htdocs/themes. Now I set up New site in dreamweaver opened the index.php file, it is running fine , but when I click on properties and ry to add or modify css property from dreamweaver, it gives me error saying unable to open file http://localhost/themes/en.css file because it is not found in the hard disk.
1. Why is it searching for file as http://localhost instead of c:/xampp/themes.
2. It says en.css file is remote file and cannot be edited.
How can I resolve this. Please guide.
you can fix this problem by browsing the file manually from its location.
When you define a site in Dreamweaver you need to make sure you set up both the local and remote locations in order for it to know where files are. It sounds like you have not defined the local site folders properly and DW is confused about where things go.
I have this path and it is correct however, the browser will not include the source file unless I put "file:///" in front of it. I'm still developing and this will ultimately be on a Linux machine but in the mean time, I'd like to see my work as well as be able to troubleshoot it. Is there a solution for this?
This fails:
C:\Program Files (x86)\work\site\js\rowlock.js
This does not fail:
file:///C:\Program Files (x86)\work\site\js\rowlock.js
Try using variable $_SERVER['DOCUMENT_ROOT'] to make your script independent. For example:
include($_SERVER['DOCUMENT_ROOT'].'/js/rowlock.js');
Works fine on any system
just use front slashes everywhere if you'll be moving this to a linux box anyway. php for windows can understand it.
$file='c:/Program Files (x86)/work/site/js/rowlock.js';
Put quotes around your path. You have spaces, so it is not read correctly.
'C:\Program Files (x86)\work\site\js\rowlock.js'
Where is Your root folder?
If its
C:\Program Files (x86)\work\site\
Then simple access your file like this
js/rowlock.js
This assuming that js is in the Root folder