Jesdisciple
08-09-2008, 08:55 PM
PS. To someone who is new to all this, can someone please explain how the edges of things are determined? Where does php end and url escaping start? Isn't url escaping part of php? How does one tell when an html phrase suddenly turns into javascript? or is that php? or sql? or maybe css? or xml? To the uninitiated it is all one big jumbled melee and I am never quite sure where to post my questions.I think this is a very good question, so I'm going to take a shot at answering it. I invite others to contribute as well.
The Web is modular, having separate interdependent parts. A module is any certain type of program, and there's a hierarchy (e.g., a browser is a type of client). These modules typically communicate with each other via strings (character sequences) which conform to patterns (data languages) understood by all involved programs. The later modules naturally build on the earlier ones, and the most basic module could be called the "core."
URLs are a data language very close to the core; every module must deal with them in one way or another. A browser/client uses them to request resources from servers (and the local filesystem); a server-side scripting language like PHP uses them to 1) request resources from either its local server or a remote server, and 2) tell the browser what resources to request.
Isn't url escaping part of php?Sort of; it's just a responsibility that PHP, along with ASP, Java, and almost any other programming language, must perform occasionally. Such a question should be posted in the forum of the language that needs to escape the URL.
How does one tell when an html phrase suddenly turns into javascript?I can think of 3 kinds of situations like this. (By the way, all of these are considered bad practice, mostly in favor of separating behavior and structure (http://www.digital-web.com/articles/separating_behavior_and_structure_2/).)
An inline script. This can be in the head, body, almost anywhere. I thought about listing the linked script, but that doesn't put JS alongside HTML.
<script type="text/javascript">alert('This is HTML-embedded JavaScript.');</script>
An event handler. As JS alongside HTML, this is always a tag attribute that begins with on.
<button value="Do something!!" onclick="doSomething();">Do something!!</button>
A URL with the javascript: protocol.
<form action="javascript:doSomething();">...</form>
or is that php?Here's a simple example where PHP might get confused with JavaScript. This file is called js.php.
var example = <?php echo $example; ?>;Where you should post a question related to this would depend upon the question. Do you not understand how $example became the value it is? That's PHP. Maybe you need clarification of why it doesn't work or exactly what it means as JS? That's JS, but I suggest you post the JS code received by the browser rather than the unparsed PHP.
or sql?SQL will normally only be in PHP/ASP/JSP or whatever server language you use. And then it will be in a string passed to a function that's obviously DB-related, like mysql_query (http://us3.php.net/manual/en/function.mysql-query.php).
or maybe css?CSS is similar to JS in this respect; it will only be found in HTML in two special cases, but both of them are considered poor practice because style and structure get mixed:
The style tag.
<style type="text/css">
body{
height: 100%;
width: 100%;
}
</style>
The style attribute.
<body style="height: 100%; width: 100%;"></body>
But CSS and JS can also get jumbled. The first case is considered bad practice if you can put it in a stylesheet. The second case is a hack that only works in IE because Microsoft needed a way to let web-developers fix IE bugs, and I took the code from http://archivist.incutio.com/viewlist/css-discuss/44263.
//This is JavaScript.
document.getElementById('example').style.width = '100%';
/*This is CSS.*/
#container {
width: expression((documentElement.clientWidth < 725) ? "725px" : "auto" );
}
or xml?I can think of two situations like this:
If you're generating an XML file with PHP, it would be like the js.php file above.
If you're manipulating the XML DOM with JS (http://www.w3schools.com/DOM/dom_loadxmldoc.asp) or PHP (http://us3.php.net/manual/en/book.domxml.php or http://us3.php.net/manual/en/book.simplexml.php), that would also be similar to the above js.php except you wouldn't be directly handling the XML. The language extension would do that for you.
The Web is modular, having separate interdependent parts. A module is any certain type of program, and there's a hierarchy (e.g., a browser is a type of client). These modules typically communicate with each other via strings (character sequences) which conform to patterns (data languages) understood by all involved programs. The later modules naturally build on the earlier ones, and the most basic module could be called the "core."
URLs are a data language very close to the core; every module must deal with them in one way or another. A browser/client uses them to request resources from servers (and the local filesystem); a server-side scripting language like PHP uses them to 1) request resources from either its local server or a remote server, and 2) tell the browser what resources to request.
Isn't url escaping part of php?Sort of; it's just a responsibility that PHP, along with ASP, Java, and almost any other programming language, must perform occasionally. Such a question should be posted in the forum of the language that needs to escape the URL.
How does one tell when an html phrase suddenly turns into javascript?I can think of 3 kinds of situations like this. (By the way, all of these are considered bad practice, mostly in favor of separating behavior and structure (http://www.digital-web.com/articles/separating_behavior_and_structure_2/).)
An inline script. This can be in the head, body, almost anywhere. I thought about listing the linked script, but that doesn't put JS alongside HTML.
<script type="text/javascript">alert('This is HTML-embedded JavaScript.');</script>
An event handler. As JS alongside HTML, this is always a tag attribute that begins with on.
<button value="Do something!!" onclick="doSomething();">Do something!!</button>
A URL with the javascript: protocol.
<form action="javascript:doSomething();">...</form>
or is that php?Here's a simple example where PHP might get confused with JavaScript. This file is called js.php.
var example = <?php echo $example; ?>;Where you should post a question related to this would depend upon the question. Do you not understand how $example became the value it is? That's PHP. Maybe you need clarification of why it doesn't work or exactly what it means as JS? That's JS, but I suggest you post the JS code received by the browser rather than the unparsed PHP.
or sql?SQL will normally only be in PHP/ASP/JSP or whatever server language you use. And then it will be in a string passed to a function that's obviously DB-related, like mysql_query (http://us3.php.net/manual/en/function.mysql-query.php).
or maybe css?CSS is similar to JS in this respect; it will only be found in HTML in two special cases, but both of them are considered poor practice because style and structure get mixed:
The style tag.
<style type="text/css">
body{
height: 100%;
width: 100%;
}
</style>
The style attribute.
<body style="height: 100%; width: 100%;"></body>
But CSS and JS can also get jumbled. The first case is considered bad practice if you can put it in a stylesheet. The second case is a hack that only works in IE because Microsoft needed a way to let web-developers fix IE bugs, and I took the code from http://archivist.incutio.com/viewlist/css-discuss/44263.
//This is JavaScript.
document.getElementById('example').style.width = '100%';
/*This is CSS.*/
#container {
width: expression((documentElement.clientWidth < 725) ? "725px" : "auto" );
}
or xml?I can think of two situations like this:
If you're generating an XML file with PHP, it would be like the js.php file above.
If you're manipulating the XML DOM with JS (http://www.w3schools.com/DOM/dom_loadxmldoc.asp) or PHP (http://us3.php.net/manual/en/book.domxml.php or http://us3.php.net/manual/en/book.simplexml.php), that would also be similar to the above js.php except you wouldn't be directly handling the XML. The language extension would do that for you.