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/"
Related
I was working on my site in php using xampp server. everything was going fine and great. i created the pages styled with css, functionalized with javascript and stored data with mysql. everything gone fine. when i decided to upload it to web server it didn't work well. on the very first page it didn't load css.
In the root directory i have only three files index.php, log-in.php and connect.php. css, js and every other files and folders are located in dashboard folder in root directory.
when i access website it shows the root index.php with no css because css files are in dashboard/ and when i access domain.com/dashboard it says
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle
the request.
I changed the files and folders permission on cpanel but that didn't work either.
This is directory structure
root index file
dashboard not accessible
should look like this
I hope somebody has explanation to this problem that why it is occurring and what is the solution.
Thank You...
I'm working in a serie of pages that (in the server) will live in a subdomain like this:
http://sub.domain.com
And I'm developing locally here:
http://localhost/subdir/
Inside this /subdir/ I have an /img/ directory with all the common images for my site (logo, background, etc.)
And inside /subdir/ I have pages like this:
http://localhost/subdir/page1/
http://localhost/subdir/otherdir/page2/
And I'm using a header.php for all my pages, then I'm calling it for every page with an 'include'.
In this header I call the image logo like this:
<img src="/img/logo.jpg">
The problem is that with this path I'm calling to the Root Directory that in the server is sub.domain.com and locally is localhost.
Then if I call the image like this works in server but not locally:
<img src="/img/logo.jpg">
And if I call the image like this works locally but not in the server:
<img src="/subdir/img/logo.jpg">
And I want to create a .htaccess file that lives only locally to redirect the Root Directory from localhost to localhost/subdir
I'm seen some solutions inside the httpd.conf in Apache but the problem is that I don't want tho change this root because I'm using different subdirs from different projects as:
localhost/subdir1 <= Project 1
localhost/subdir2 <= Project 2
My question is how to redirect this Root Directory using the .htaccess to make this image calls works in the server and locally?
Of course I was looking and trying but I cant find the solution in other questions here or in othes sites.
Thanks in advance.
We recently have adquired the credentials to fully play with our website hosted outside.
So we need to mount it locally on a XAMPP stack to fully deploy the site and asociated database.
It've been already done, and everything seems to work properly except for the images in the site.
It is a DRUPAL site. Some images are "full path coded", so they work as we can expect, but major of them are just relative path coded.
Now, I've everything mounted on localhost. Let's say the folder with the site it's called "web".
Then i've everything on:
c:/xampp/htdocs/web/.......
So I access to it via: http://localhost/web/
I've tested that all the non viewing images, if I append the "http://localhost/web/" on the 'src="/site/..."' they are accessible and look right.
So, is there a way to via .htaccess add the "http://localhost/web/" on those URLs who hasn't it? It doesn't only happens with images, it's just related with all the links, urls, srcs, whatever which is just "relative pathed".
I've already tried the "RewriteBase /web", but it doesn't work.
Need help to solve this so, please.
In summarize, the site online is just mounted on the root, so everything works, fully or just relativetly pathed. But in my case, I've got the development site inside a folder, so I need it to work too!
Much appreciated.
If this is a Drupal 7 site (might work for Drupal 6) make sure you have a tmp directory set. Go to admin/config/media/file-system and look for the temporary directory. Also confirm that you have this directory on your root, which for XAMPP is the htdocs folder.
This might be a file permission that can be caused by incorrect .htaccess settings (This link may help: https://www.drupal.org/node/2140629) in the folder set as your temporary directory.
This may also be a document root error. You can change that by editing the DocumentRoot setting in C:\xampp\apache\conf\httpd.conf.
This stackoverflow link may help if none of the above suggestions bear fruit: https://drupal.stackexchange.com/questions/30113/configuring-the-temporary-directory
For some reason when I create a project in netbeans and go to run the project it also loads the xxamp index file and not the project index file that is apart of the codeigniter installation.
http://screencast.com/t/qOSH80wPgvf
Edit:
Here is my file tree I have right now set up for my project. Why Netbeans creates an important files folder I have no idea for my CI project. I have edited the index file to have the application and system variable to both have the ../system or applicaton as its value. I have changed the Web Root inside the project properties to have a value of public_html and I have also changed the value of the Index File field to say index.php.
After doing this and running the project I would expect to get the default Welcome to Codeigniter page and I don't. I am receiving a message that shows the following. Any ideas on why this is?
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
Projects
- MyFirstProject
- Source Files
- application
- public_html
- assets
index.php
- system
- Test Files
- Important Files
- Include Path
I've tried doing some additional research on the topic and have yet to come up with a solution.
Edit 2:
Any ideas from anyone?
Your problem is likely related to your choice of folder layout. Which I assume you do, for "security reasons". That said, NetBeans isn't a server. Its an IDE, so you can't manipulate it the same way you would the server.
Most servers by default define your "root" folder as "public_html" or "www" as far as where it looks by default to serve files for public consumption. Through the use of PHP you can tell the index.php that comes with CodeIgniter to look up one directory outside of the defined root and have it read the file(s) accordingly.
However, to setup a project in netbeans and have all files and folder accounted for accordingly you need to tell it that all your files start in whatever folder they reside. So it can load all the files and read from them respectively. This in essence and in respect to server logic is telling it that the folder that houses
application
public_html
system
is the define root path. So inadvertantly by breaking out of the design of codeigniter and placing the core files outside of what would be your defined root on the server is breaking your project. There is not an index.php depicted in your listing above at the same level that those folders are in. If there is, its the index.php for xxamp that keeps loading for you by default.
What you need to do is stop trying to implement your "security measures" and put them in the right order. Or.. not include that folder in your project telling it the one with assets and index.php is the root path. If netbeans is smart enough it will find the files and folders outside like the server will.
Right click on your project and go to properties. Make sure that in the run configuration the URL is correct and the index file is properly set up and matches your directory in xxamp.
after downloading codeigniter open index.php file and there set your path correctly to your
application folder because i think you putted your index.php inside public_html folder so
the path which is set by default in index.php is not working and can not find application folder, try to fix it and it will work fine your problem is not with netbeans.
I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp.
now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html'); it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it works perfectly and opens the file. below is my test code
<?php
echo 'headerfile';
include('/template/header.inc.html');
?>
if I give the full path for example C:/wamp/www/template/header.inc.html to the include function it works fine.
I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost
I would appreciate any help that would clarify my confusion, Thanks.
Absolute paths on the server start from the server's hard disk (C:\).
Absolute paths on the client start from the root of the website (http://example.com/).
You can make use of __DIR__ to make some file on disk relative to the php-file on disk itself:
include(__DIR__.'/template/header.inc.html');
This should solve your issue.
The difference is not that easy to explain because both types of paths - even related - are two pair of shoes. I suggest you start with a very basic HTML website tutorial that explains how to link on your website and where files are located and how that is related to the webserver configuration.
HTML pages live in the client's browser that know nothing about your server's folder structure, and they're relative to the domain name eg. http://example.com/.
PHP programs run on the server side and they deal with the server folders. You shouldn't hardcode full paths in your php programs, because it will cause problems whenever you'll move them between the development server and the live host (just to name an example). Therefore in php files you should either use relative paths to your file, or use the __DIR__ magic constant that gets substituted with the directory where the php file is.
1.) First approach: include('template/header.inc.html');
2.) Second approach: include(__DIR__ .'/template/header.inc.html');
In your case (working on a development machine) both the client and the server is the same box, that might be confusing you.