PDA

View Full Version : PHP/ASP/Javascript snippet for including/import



aw1zard2
13 Oct 2009, 8:34 AM
I've been using this code for a while and someone at my office asked me about it today and figured I would share in case anyone else wanted to use it. I'm just gonna do a small php example. Can be used with any number of program languages.

I name my php file alljs.php below is its contents.


<?php
header("Content-Type: text/javascript");
include "../ext3/adapter/ext/ext-base.js";

if($_GET['debug']){
include "../ext3/ext-all-debug.js";
} else {
include "../ext3/ext-all.js";
}
?>Then in the html <head> of a web page either dynamically built by php or static I do the following code below:


<script type="text/javascript" src="alljs.php?debug=1"></script>This makes it easy to have 1 file available for editing paths to any JavaScript file needed.

I have a more complex one I use which has more logic in it depending on the page name calling and different options. It also checks for the user to be logged in and ip/sessionid security as well so no one can hijack it. But this simple example gives you the idea.

Enjoy!!

:)