| a | b | |
|---|
| 0 | + | // Pointless commenting example: |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | $username = mysql_real_escape_string($_POST['username']); # Get username |
|---|
| 0 | + | $password = mysql_real_escape_string($_POST['password']); # Get password |
|---|
| 0 | + | $age = intval($_POST['age')]; #Get age |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | |
|---|
| 0 | + | // The above is useless because it's quite obvious of what's happening. |
|---|
| 0 | + | |
|---|
| 0 | + | // Useful commenting: |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | # Get information from POST |
|---|
| 0 | + | |
|---|
| 0 | + | $username = mysql_real_escape_string($_POST['username']); |
|---|
| 0 | + | $password = mysql_real_escape_string($_POST['password']); |
|---|
| 0 | + | $age = intval($_POST['age')]; |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | |
|---|
| 0 | + | // This way saves time. |
|---|
| 0 | + | |
|---|
| 0 | + | // Also, a good place to put comments, is when you're making a new function or class. |
|---|
| 0 | + | // Describe the inputs and outputs a bit. |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | |
|---|
| 0 | + | /* |
|---|
| 0 | + | Function: salt_crypt |
|---|
| 0 | + | Desc: Encrypts a string using a salt. |
|---|
| 0 | + | Inputs: |
|---|
| 0 | + | $string (string): The string to be encrypted |
|---|
| 0 | + | $salt (string) : The salt to use. |
|---|
| 0 | + | */ |
|---|
| 0 | + | |
|---|
| 0 | + | function salt_crypt($string, $salt) |
|---|
| 0 | + | { |
|---|
| 0 | + | $return = md5(md5($string) . $salt); |
|---|
| 0 | + | return($return); |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | // ---------- |
|---|
| 0 | + | |
|---|
| 0 | + | /* |
|---|
| 0 | + | |
|---|
| 0 | + | Why comment like that at the beginning of a function? It will save a lot of time. Saves the person reading from having to go through the code for that function. |
|---|
| 0 | + | |
|---|
| 0 | + | */ |
|---|
| ... | |
|---|