Jump to content

Recommended Posts

Posted

Straightforward background: I'm using FrontPage 2000, and writing the JavaScript I need directly into the HTML panel. There's no problem with this :-)

 

But, since there are certain functions I use on every page, I'd like to include some basic functions rather than repeat the function.

 

I can create the file (say, 'commonfunctions.js'). The question is, where do I put it? I'd prefer it not be directly openable or viewable by others. I'd also like to be able to refer to it with a relative path if possible, or at least, not something so hard-coded I'm going to regret it.

 

If life were really nice :-), I'd be able to use it from subdomains as well as my main domain. (I don't have a subdomain yet, but I'm thinking ahead.)

 

Also looking ahead, would PHP standard functions go in the same directory as the JavaScript ones? (or at least off the same top-level location?)

 

And for a final question (this one is more FP specific), where do I put them on my own machine so that I can run them during development as well as having them available at production?

 

Thanks!

--Beth

Posted
I can create the file (say, 'commonfunctions.js'). The question is, where do I put it? I'd prefer it not be directly openable or viewable by others. I'd also like to be able to refer to it with a relative path if possible, or at least, not something so hard-coded I'm going to regret it.
You can't really hide JavaScript code from the viewers of your site. The code is executed by the web browser, so it has to be downloaded to their machine. Even if you could keep them from viewing the .js file on the server, they could always pull it out of the browser cache and look at it. The best place to put JS include files in either in your public_html or a subdirectoy of public_html.

 

Also looking ahead, would PHP standard functions go in the same directory as the JavaScript ones? (or at least off the same top-level location?)

PHP include files should definitely be kept in a directoy that is not publicly viewable; i.e., outside of public_html. Since PHP runs on the server, and can access files on the server, allowing people to view your PHP code can pose a security risk.

You could create a directory for your PHP include files at the same level as public_html. For example, /home/user_name/php. Then put a line like this in your .htaccess file:

 

>php_value include_path .:/home/user_name/php

 

This adds the directory to PHP's include path, so you don't have to reference the file by it's absolute path. Take a look at the PHP Manual for more information.

 

HTH

 

Rob

Posted

Please don't send me back to school! Please!

 

These aren't really coding questions--they really are "where do I put the files on my host" question.

 

How about if I rephrase my primary question, since I swear it's quite simple:

 

My website, of course, is under the 'www' directory.

If I want to create a directory to store my common JS files so that they can be included by files within my www web, where would i create that 'common' directory? Does it go under 'www', or under the top level?

 

(These are the kind of stupid questions that come up when moving from a defined-production environment)

 

--Beth

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...