Total Pageviews

Wednesday, April 27, 2011

ITC 280 – Class Notes 4-27-11

... some stuff missing here (back track on eluminate later)
Config file – where to turn on/off error msg
                Doesn’t have to depend on a database to have it work
MySQL(continued):
Assignment 4:

Lesson 9 – Unix, Command Line, File Permission (continued)

Re-captcha : takes magazines form the past and tries to do an optical scan of words…. It goes in a database, where one word needs to get right, the other word is unknown
                Repurchased by google, as a project
Unix: IDEAL, and have been around longer(takes less deal of brainpower to get it up and running)
-         Free, accessed anywhere
-         Hosting hardware – web server software (apache)
Windows: IIS  (web software version)
-         Command line - Can speak directly to server (do almost everything with some limitations)
-         Ports: (doorways to servers)
-         Use the real name, no http:// protocol

Database and web server NOT always on the same machine
 (security & accessibility)
            Number of web servers to MySQL servers- 4 (servers) : 1 (database)
-         Can re-allocate the work load better if different machines have dedicated storage

drwxr-xr--
d - directory
rwx – Owner/you, whoever is logged in
 
(if on web, “you” are unknown, you are “everyone” or “public”)
     (note: owner doesn’t automatically get full access)
r-x Others to access (to run/open img files)
r-- what the public can do to your file

Values

rwx = 4 + 2 + 1 = 7
rw- = 4 + 2 + 0 = 6
r-x = 4 + 0 + 1 = 5
r-- = 4 + 0 + 0 = 4
r has a value of 4 = read
w has a value of 2 = write
x has a value of 1 = execute
- has a value of 0 = not applicable

Uploading a file is dangerous (web browser will treat files as best as it can base on the file extension)

Viewing permission files in zephir looks something like this:
NOTE: always try and change your file permission on the server, only change it when you know better

Trust the server but notice what it does

Different hosting servers will give you error permission guides





Setting files recursively – go through the entire folder and repeat itself

Directory browsing: when there is NO index 

Speed of operation: “not in fashion”
   only build a database when necessary- databases are slower to load (ideal is small)
MySQL Moniter - command line in MySQL 

Building a database:

Entity > Attribute       (list of the item & view it within the same page)
Tables > Fields            (how it’s stored in the database)
Object > Property

Structured Query Language:

-         Each piece gets broken up into columns
o   CustomerID (stays the same)
o    LastName
o    FirstName
o   Email

Primary key: is NOT inherently known to computer
Example: (written like this)
create table test_Customers
( CustomerID int unsigned not null auto_increment primary key,
LastName varchar(50),
FirstName varchar(50),
Email varchar(80)
);

Naming Convention: No space, CamelCase or underscore, NO funny characters
-         Semi-colon: ending the statement (can me a multiline, but semi-colon ends it)
-         Commas: separate the attributes
-         Comment: # sign or /*    */

MySQL Data Types:

-         Char(number): fixed length string
-         Varchar(number): variable length string with max indicated (with Strings)
 entry can’t exceed this number (individual data name)
·         Truncate – chops off the last characters that exceeds (silently, without exploding)
-         Int: used for numbers
-         Null( nothing was ever there) versus not null (something was there but is now empty)
-         Text: field designed to accept 65,000 char
-         Blob: field designed to accept large fields/ image data, etc

Structure internally of a database:

.sql – file extensions for MySQL file

MySQL (continued):
Log on with putty:
            horsey01 > 6 SID > mysql –u horsey01 –p > my_sql_password
use horsey01  to

-         % is a wildcard symbol, it represents any symbol

Monday, April 25, 2011

Class Notes 4-25-11

Arrays:
·         Mechanism that can expand or shrink to any size that collects data
·         Keeps it in a set
·         Can be all kinds of data types, doesn’t have to all match
·         Taking care of the order & the key that uses to identify it.
Associative array: manually takes care of the index, & the number of elements in the array
$aPicnic = array('Sandwich'=>'Turkey','Drink'=>'Pop','Dessert'=>'Cupcake');
Note: arrow has NO space, must be >
function makeLinks($linkArray)
{
    $myReturn = '<ul class="links">';
    foreach($linkArray as $url => $text)
    {
        $myReturn .= '<li><a href="' . $url . '">' . $text . '</a></li>';  
    }  
    return $myReturn . '</ul>';  
}
Rotation: pieces of content that rotates through (with modulus widget) to allow pages appear dynamic
Unix, Command Line, File Permission
Designed to run on nothing, does not require OS or much hardware
Web server: simple piece of hardware, hands files to you
Web hosting vs mySQL server:
NOTE: To be able to talk to a server, you need a SECURE connection & know the commands
REQUIREMENTS:
1.       zephir.seattlecentral.edu
2.       Horsey01
3.        

File Permission:

3 levels of access:
 Read(see it but not change it),
write(lets you write it but you can’t see it), &
 execute (For a program to run from the server, a file or directory may need to be set to have "execute" capability. UNIX is aware of running programs, and will disallow access to a program if the execute permissions do not allow access)
Read/Write Execute (RWX): The 3 permissions described above make up rwx, read-write-execute, which apply to directories and files, all of which must be set properly for our PHP web applications
Files (controls itself) & folders(controls the content within it) both have file permission involved
Unix Permission Values:  7 is the lucky number
     (when a file has all 3 levels, contains a 7 permission value)
·         Read = 4
·         Write = 2
·         Execute = 1
Therefore, for full RWX access to a file or folder, we would set it to 0777, which is 'world writable' and the riskiest possible setting. (only time you need 7 in the last number, when you aren’t able to upload the file

  drwxr-xr--       4096    Aug 31 22:32    myDirectory
directory or not

d or -
owner-'s access: Non-event

rwx 
Public (what is on web)
Is this file world writable? (7 is indicator)
·         Most cases is a 5
(read/executable)
·         Images wont show up if 5 isn’t here

COMMANDS:
d: stands for directory
rwx : permission of the owner
r-x :permission of the group,
       means 5 (read & executable)
r-- : permission of everyone else
      means 4 (read permission only)
chmod: change mode                    ex: chmod “filename” 0777 (changes the file permission to ‘world writable’

Windows: Putty          Mac: Terminal

Logging onto Putty, make sure you click “never” when you’ve never logged on this computer before (“close window on exit”)

Permission set:
   -rw-rw-r--
1st – d or a dash –
2nd
3rd
4th – 2 is dangerous (writable), 3 dangerous
      4 is ok (readable)
      5 is ok
      6 is dangerous
      7 is dangerous





NOTE: the cursor does not move
Domain is controlled by Seattle Central (email address network login)

“ ~ ” represents “root”

 Password needs to be created for mySQL
 (mySQL on zephir)
            (same as email password)

Then you type in:
  mysql –u dpham004 –p
         (password here)




Authentication: I know who you are (your account exists)
Authorization: can you touch file or not (permission settings)
MySQL monitor:  Command line in MySQL



“database changed” means it grants who gains access


Deletes the table of
Dump means “cut” and put it somewhere else
> use dpham004
>  show tables;  (stores like things)
> show databases; ( )
>  drop table test_Customers;




Database: is like engine of the car, what makes it run
                you are designing the schema & structures of the database

Portable Programs:

  • ·         Portable version of firefox
  • ·         Putty
  • ·         Notepad++
·          
·          

Assignment 4: Email form handler: ReCaptcha (recognizes people from robots, sustainable string docs)



Wednesday, April 20, 2011

ITC 280 - Forms Get, Post / Arrays & Superglobals


ITC 280 – Class notes 4-20-11

Programs:

·        EditPad Pro (www.jgsoft.com)
o   AceText (holds the stuff from your clipboard, in sync with EditPad Pro)
·         www.portableapps.com  (portable version of firefox & all the open office suite & a pdf viewer)

Web Applications review:

Postback string does NOT show up on the page
Web applications can transmit two ways:
Get:       default method, not as secure
                good for a loaded query page
                data being sent is visible
                Will go back to default if developer accidentally
 
Post:      sends data in a non-visible way
                better at forms

Forms: (floating in memory)

“name” attribute is how to find/get access to the form
“postback” goes back to the same page
To send data back to the machine back to server
Form elements: see http://saranewman.com/web110/web110form-ppt/web110form-ppt.html
see also:
    Constants: accessible everywhere (global)        
Superglobal:    all piece of the data that was sent from the user is now called a “superglobal”
         “$_...” – indicator of a superglobal

          Definition: a variable that is available to you that is a result of a “post”
                      
superglobals are arrays!
·         $GLOBALS
·         $_SERVER
·         $_GET
·         $_POST
·         $_FILES
·         $_COOKIE
·         $_SESSION
·         $_REQUEST
·         $_ENV
$_POST['varName']      //name attribute MUST match

NOTE: $_GET and $_POST are NOT the same
            web server – controls the address …
if(isset($_POST['FirstName'])  // to see if there is data
{
     $myVar = $_POST['FirstName'];
}
action:”blah.php”
Assignment 4: contact form with Recaptcha (ferrets out web robots)
NOTES:
web – by default is a stateless environment
Cookies: string of data that uniquely identifies the person (part of http & html)
            they are for your security
            also are known as superglobals
            Session” – piece on the server that matches up to the person globally
Server Log: tracks the number of users, number of unique visitors, browser that is used, search engine, search term, website that they used to get to your site
   Hosting company: Urchin (owned by google, that is on the server)
       > Usually only available are for a week (so they get deleted after)
             > Find out how much traffic they have, take a snapshot of the data before it disappears

Arrays:

·        All important data comes from this format, an alternative way to store a set of variables
   constants – can only store one piece of data at a time
·        Like a file folder (groups the data) and can grow to virtually any size!
Type of data storage: flexible, allows the following to be stored
            strings
            numbers
            Boolean
            arrays             (within another set)
              > array (within another array)

Practice:

array_practice1.php // database stores & gives us the array
indicator for an array (suggested by Bill)
                “$a…” = array( );
ex:
<?php
//array_practice1.php
$aFruit = array("bananas",56,"oranges");
print_r($aFruit); // print_r is the command to print the array
?>
Displays:
          Array ( [0] => banana [1] => 56 [2] => oranges )
               // c style code and starts in 0, not at 1
                (built by AT&T, language C)
Offset: how far off it is from the beginning (zero is the start)
index: to what it means to humans  (what position it is actually in, “0” means 1st element in array)
key: unique identify      data/value: on the right side of the equal sign
<?php
//array_practice1.php
$aFruit = array("bananas",56,"oranges");  
echo '<pre>';       
//formats the array like how it should look, open <pre> tag
print_r($aFruit);    // print_r is the command to print the array
echo '</pre>';            // must end pre tag,
php is ignorant of <html> but can use it
?>
Line break:              <br /> for <html>
carriage returns:  don’t exist in <html>

Ways to print an array:

print_r: way to look at an array
var_dump: look at anything
Backtrace: like a var_dump for the entire data, dump of the entire server at that moment

var_dump result: 

array(3) 

{
  [0]=>
  string(7) "bananas"
  [1]=>
  int(56)
  [2]=>
  string(7) "oranges"
}
Cheese array exercise:
$aCheese = array();
$aCheese[0] = "cheddar";
$aCheese[1] = "brie";
$aCheese[2] = "brie";
$aCheese[] = "mozerella";
$aCheese[] = "brie"; //fastest way to add a new variable to an array
$brieCounter = 0; // neutral value, empty number for an int
foreach($aCheese as $slice)
{
     echo $slice . "<br />";   
     // how many times does 'brie' string shows up in the array
     // if it does equal, increment the brie counter
     if($slice == "brie")
     {   
// if the current array value = 'brie', add 1 to the counter
        $brieCounter = $brieCounter + 1; // increments the number of bries
        $brieCounter += 1;     
// another way of writing the incrementation     
   $brieCounter++;     // shortest version if you are only adding by 1
}
}
Most efficient way to access an array is with a “for” loop:
for($x=0;$x<count($aFruit);$x++)
 {  
     echo $aFruit[$x];   
 }
1.      Start at the beginning
2.      Until you get to the end, continue until you get to the end
a.      “count” is a function (like getlength)
b.      Loops through the array called “aFruit”, $ is the indicator of the array variable
3.      Increment by 1, go one at a time
Another way:
$aCheese = array();
$aCheese[0] = "cheddar";
$aCheese[1] = "brie";
$aCheese[2] = "swiss";

 for($x=0;$x<count($aCheese);$x++)
{
   echo $aCheese[$x] . '<br />';   
}

Alternative way to have a for loop:
foreach($aCheese as $slice)
{
    echo $slice . 'br />';  
}