sparks wrote:
Hardmath, I like the NEW! idea
![]()

Offline
sparks wrote:
That just hurts my eyes
![]()
Just an idea... It hurts mine, too. Maybe text will suffice.
Offline
WindowsExplorer wrote:
AAA! Seizure!
...
Offline
Some JS stuff:
Use MDN and not w3schools
In almost every case, it is better to use the identity operator than the equality operator[/url] because the equality operator behaves strangely. Leaving out semicolons is a bad idea, because odd things can happen:
var a; a = 2 (a + 2).toString(); // throws a TypeError because 2 is treated as a function // same as: a = 2(a + 2).toString();
Self-evaluating (or self-invoking, etc.) functions are closures (functions without names) that call themselves in the expression they're created in. They're incredibly useful for controlling scope:
(function () { // construct a closure...
var a = 2;
console.log(a); // 2
})(); // ... and call it
console.log(a); // a is undefinedMethod calls are really just a property access + a function call:
(function () {
var foo = window.alert; // property access
foo(2); // function call
})();The "global scope" means the window object in most cases - it's the place variables are looked up/defined if they're not found elsewhere:
var foo = 2; // window.foo = 2
(function () {
var bar = 3;
console.log(bar); // 3
console.log(foo); // 2
})();The "window" object actually has a "window" property, which is what is being accessed when you use window without defining it elsewhere. It is perfectly legal to do that anywhere but in the global scope:
window = 'foo';
console.log(window); // the window object
(function () {
var window = 2;
console.log(window); // 2
})();JavaScript actually uses prototypal inheritance (a different system of inheritance than classical, which is what programming languages like Java and Smalltalk use). This means that any object can inherit from any other object:
var foo = { // object literal; constructs an Object with the properties between the braces
a: 2
};
var bar = Object.create(foo); // create a new Object which inherits from foo
// properties which are not part of objects are looked up in their prototype, and that object's prototype, and so on
console.log(bar.a); // 2
// you can change an object's prototype's property (or add/remove) one,
// and the change is visible in the objects which inherit from it
foo.a = 8;
console.log(bar.a); // 8
// it's fine to define properties that are present in an object's prototype
bar.a = 3;
console.log(bar.a); // 3
// ... but doing this has no effect on the prototype
console.log(foo.a); // 8The new keyword creates a new object which inherits from its argument's prototype, then calls its argument (a function) with that object as the value of "this"
function F() {
this.a = 2;
}
var foo = new F();
// same as...
var foo = F.apply(Object.create(F.prototype));Apply is a method of Function objects which applies the function to the given arguments (an array, the 2nd argument) using the 1st argument as the "this" value)
When making constructors, use the prototype object, because:
1) all instances of the constructor inherit their methods from one object (this uses less memory)
2) all instances' methods are identical--they are the same object, rather than being functions which have the same contents
function UsePrototype() {}
UsePrototype.aMethod = function () {
console.log('hi');
};
function DontUsePrototype() {
this.aMethod = function () {
console.log('hi');
};
}
var a = new UsePrototype();
var b = new UsePrototype();
a.aMethod === b.aMethod; // true
a = new DontUsePrototype();
b = new DontUsePrototype();
a.aMethod === b.aMethod; // falseThe naming convention is to capitalize constructors:
function Constructor() {} // constructor!
new Constructor();
function someFunction() {} // not a constructor!
someFunction();EDIT: I will probably write a prototype-based JS tutorial soon, explaining things in more detail.
Last edited by nXIII (2011-11-13 15:24:18)
Offline
Thanks, n, that's certainly going under "Hard" as a tutorial difficulty, I hope that's what you had in mind as a lot of things are taken for granted that you know
You have a loose[/url] tag on the 4th line of text, too
Otherwise, very good!
Offline
hmm this is pretty cool! I have some html things worth posting.
Offline
^ Home
HTML — False Floating Windows
Difficulty: Hard
False Floating Windows (FFWs) are fake windows within an HTML page. This can be useful if you want to, for example, bring up a pop-up with a customized interface.
To begin with, let's start with some CSS:
div.FFW
{
position: absolute;
top: 0;
left: 0;
z-index: 1000;
}All this does is make sure FFW class divs 'float' above the page.
Now, let's add the div to a page:
<div class="FFW" id="myWin">Hey, there!</div>
Notice how the text on the window covers up text on the document. Let's add this line in our CSS to prevent that by adding a background to the whole div.
background-color: #FFFFFF;
The div shrink-wraps into the text. Let's give it a structured width:
width: 300px;
Now let's add a toolbar. Put this inside your <div>:
<div id="toolbar-myWin" style="background-color:blue;"><button onclick="document.getElementById('myWin').style.display='none';">(x)</button></div>All together now:
<style type="text/css">
div.FFW
{
position: absolute;
top: 0;
left: 0;
z-index: 1000;
width: 300px;
background-color: #FFFF99;
}
</style>
<div class="FFW" id="myWin"><div id="toolbar-myWin" style="background-color:blue;"><button onclick="document.getElementById('myWin').style.display='none';">(x)</button></div>Hey, there!</div>Last edited by Hardmath123 (2011-11-14 08:42:37)
Offline
Nice tutorial, Hardmath123, IDK if this is just because of my viewpoint, but I would class that as a moderate not hard tutorial
It's very good!
Last edited by sparks (2011-11-14 18:44:06)
Offline
sparks wrote:
Nice tutorial, Hardmath123, IDK if this is just because of my viewpoint, but I would class that as a moderate not hard tutorial
It's very good!
Though I agree the tutorial itself is moderate, I can't really think of anything harder for just HTML. Here's how I would group HTML tutorials:
Easy
• Explains one tag or attribute's usage or special trick.
• Written for somebody with no/little background knowledge in HTML
• Does not have references to other languages (CSS/JS/PHP)
• Mainly teaches how to add visual effects (eg borders)
Moderate
• Involved grouping of many elements and attributes
• May need some background knowledge
• Uses some CSS styles
• Adds interactivity that doesn't need (much) programming (eg change anchor color on rollover)
Hard
• Involves many nested or grouped elements
• References from many languages (JS/CSS/PHP)
• Needs lots of background knowledge about how many special elements work
• Adds interactive effects that need programming (eg search bar)
EDIT: I think you need a CSS section, too.
Last edited by Hardmath123 (2011-11-15 08:54:08)
Offline
I need help. (I'm PF, btw)
Um, so yes. This is a blog app that stores each post in the xml file, posts.xml.
Currently, it is not reading....
<?php
//blogify.php
//Blog App.
//Made by ProgrammingFreak
$app = "Blogify";
$style = "
#blog_app{
max-height: 600;
max-width:900;
height: 600;
width: 900;
display: none;
background-color: #4B79AD;
}
#blog_app button{
background: #1e5799;
background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 28%, #207cca 51%, #7db9e8 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(28%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8));
background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: -o-linear-gradient(top, #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
background: linear-gradient(top, #1e5799 0%,#2989d8 28%,#207cca 51%,#7db9e8 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 );
border-style:solid;
border-color:#1e5799;
color: #fff;
}
#menu{
background-color:#1e5799;
width: 900px;
}
#menu img{
margin-left: 5px;
margin-top: 5px;
margin-bottom: -5px;
}
";
echo <<<_END
<html><head><style>$style</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get("data.php", function(data){
$("#blog_app").fadeIn(2000);
$('#blog_app').html(data);
});
});
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","pages.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
$("#content").html(xmlDoc.childNodes[0].nodeValue);
$("#content").html("hello");
</script>
</head><body>
<div id='blog_app'>
</div>
</body></html>
_END;
?>//posts.xml
<posts>
<post>
<author>%uservar%</author>
<content>Welcome to Blogify.</content>
</post>
</posts><?php
//data.php
echo <<<_END
<div id="menu">
<img src="logo.png" height="20px" width="20px"/>
<button id='new'>New Post</button><button id='del' onclick>Delete Post</button>
</div>
<div id="content"></div>
_END;
?>Thanks.
Offline
bump
Offline
Has it read the xml file before? If it has, I'm not sure. If it hasn't, maybe put the file into a variable?
Offline
Magnie wrote:
Has it read the xml file before? If it has, I'm not sure. If it hasn't, maybe put the file into a variable?
Okay, I'll try that...
Offline
In true search engine guruing and great memory, I am posting this question in a relevant thread!
Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.
See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM
Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????
Thanks,
Sparks
Offline
sparks wrote:
In true search engine guruing and great memory, I am posting this question in a relevant thread!
Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.
See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM![]()
Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????
Thanks,
Sparks
You verify the name and a "key" with the database or something similar.
What I've done is, when a user logs in, a random (probably best to make a truly random) key and save it to the user's cookie and to the database. Then check the key and username against the database.
Only problem with this method, is that user's can copy the cookie onto another computer and it will work for them. But that is true for all websites.
Offline
Right. First of all, there is no such thing as true random, so what do you mean by that? Will the php rand() function do? And in that case, wouldn't a hash of their password do as well? (thank you
)
Offline
sparks wrote:
In true search engine guruing and great memory, I am posting this question in a relevant thread!
Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.
See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM![]()
Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????
Thanks,
Sparks
You could hash the password and store that and the username (or use a random key, although just hashing means you don't need to store any additional data); alternatively you could store the session ID in a cookie. That way, if the cookie was copied to another computer, it would only work while the user was still logged in.
Offline
nXIII wrote:
sparks wrote:
In true search engine guruing and great memory, I am posting this question in a relevant thread!
Does anyone know much about cookies? I wanted to get cookie based login working on my website. Then I got really confused.
See, cookies are just little text files stored on your computer. So what's to stop me storing a cookie with the username of the last login in it? Nothing. But then the user could simply change the contents of the cookie with a text-editor so that the name matches another user, then get logged in AS THEM![]()
Similarly, if I stored the password too, that's a huge security hole for THEM as that cookie can then be used by anyone to log in, just by copying it. No web pages I have found seem to answer this problem, so how can I use cookies for logging in without posing a security risk for either myself or the user????????
Thanks,
SparksYou could hash the password and store that and the username (or use a random key, although just hashing means you don't need to store any additional data); alternatively you could store the session ID in a cookie. That way, if the cookie was copied to another computer, it would only work while the user was still logged in.
That's a good idea! Wouldn't the session id change when the session expires though?
Offline