admin管理员组文章数量:1319953
I'm following this tutorial to create a safe login system. My folder logic is as follows:
/var/www/html/mysite/ # html folder is public (here goes index.php, etc)
/var/www/includes/ # includes is hidden (login details, etc)
/var/www/js/ # js is also hidden, as stated on the tutorial
When I say "as stated on the tutorial", I refer to this passage:
Store your copy of this file in a directory called "js", off the root directory of the application.
Did I interpret it right? Should js folder be inside html, instead of www? What's the difference? In my code, I have lines like:
include_once '../../includes/db_connect.php';
include_once '../../includes/functions.php';
and
<script type="text/JavaScript" src="../../js/sha512.js"></script>
<script type="text/JavaScript" src="../../js/forms.js"></script>
While the php includes work nice, the javascript ones don't. Firefox inspector is plaining:
GET http://localhost/js/sha512.js [HTTP/1.1 404 Not Found 0ms]
Why is it considering that my js folder is inside html folder, and not where I'm telling it?
I'm following this tutorial to create a safe login system. My folder logic is as follows:
/var/www/html/mysite/ # html folder is public (here goes index.php, etc)
/var/www/includes/ # includes is hidden (login details, etc)
/var/www/js/ # js is also hidden, as stated on the tutorial
When I say "as stated on the tutorial", I refer to this passage:
Store your copy of this file in a directory called "js", off the root directory of the application.
Did I interpret it right? Should js folder be inside html, instead of www? What's the difference? In my code, I have lines like:
include_once '../../includes/db_connect.php';
include_once '../../includes/functions.php';
and
<script type="text/JavaScript" src="../../js/sha512.js"></script>
<script type="text/JavaScript" src="../../js/forms.js"></script>
While the php includes work nice, the javascript ones don't. Firefox inspector is plaining:
GET http://localhost/js/sha512.js [HTTP/1.1 404 Not Found 0ms]
Why is it considering that my js folder is inside html folder, and not where I'm telling it?
Share Improve this question asked Oct 21, 2015 at 18:30 RodrigoRodrigo 5,13910 gold badges59 silver badges103 bronze badges 6-
..
depends on the file location of the file it's used in. It looks like your HTML file is inside thehtml
folder, and hence going back twice leads you to the root and not towww
. Although for a devident answer you are going to need to show us where that HTML file and PHP file is in your directory. – Spencer Wieczorek Commented Oct 21, 2015 at 18:34 -
use absolute path: instead of
../../js/forms.js
use/var/www/js/forms.js
if /is the root of your server. – Ayush Gupta Commented Oct 21, 2015 at 18:37 - The file location is /var/www/html/mysite/, so the ../../ is right, just like for the php includes. – Rodrigo Commented Oct 21, 2015 at 18:37
- @Rodrigo try giving the absolute path with respect to root of your server. – Ayush Gupta Commented Oct 21, 2015 at 18:38
- @Rodrigo That doesn't mean it's right. Especially if your HTML file and PHP file are in different locations. – Spencer Wieczorek Commented Oct 21, 2015 at 18:38
2 Answers
Reset to default 4I would try putting the JS inside of the html folder and linking to it like this. <script type="text/JavaScript" src="js/forms.js"></script>
If the www
folder is the root directory (i.e. the folder used for http://your-url/
) then you can do the following:
<script src="/js/sha512.js"></script>
<script src="/js/forms.js"></script>
The leading /
says "start at the root of the website".
If the html
folder is your root directory, you'll need to move the js
folder into the html
folder - and you can still use the script tags shown above.
JavaScript files are requested by the browser, and the folders outside the root of your website are forbidden to the general public. Your PHP files are loaded on the server, which means you are able to see files the general public does not have access to.
本文标签: Can39t I put my javascript files outside html public folderStack Overflow
版权声明:本文标题:Can't I put my javascript files outside html public folder? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742058919a2418464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论