Cookies Uses Size limit what to do if turned off Can they be trusted? When can you set them in PHP Session Vars Use one cookie Store data locally Language dependent Login passwords always encrypted! probably set a session var or cookie if cookie Pick random number Verify random number Know this is vulnurable to snoop attack Data verification Javascript gives a good user experience but cannot be trusted Server side can be trusted. AJAX What is AJAX. What happens on the client and on the server. How to do it (basics). SQL ACID properties Atomic -- The transaction runs completely or not at all Consistent -- Each transaction moves from one consistent state to another Independent -- Every transaction runs as if it were the only one on the system Durable -- Data changes survive hardware and software failure. Abort Table vs database create table schema not null primary key types decimal(5,2) date and time types enum blob/longblob char[n] vs varchar[n] money autoincrement update tablename set columnname = value where ... delete from tablename where ... select columnname from tablename where .. order by columname limit 3 alter table ... drop tablename describe table tablename joins nested queries (and in vs =) min and max count and average and group by insert into tablename values ( ...) database decomposition might cost speed reduces redundency and possibility of inconsistency Indexes What is an SQL injection attack (i.e. little bobby tables)!!!! Should media files be in the database PHP Built in arrays $_GET $_POST $_COOKIE $_SESSION $_REQUEST Error supression with @ isset($varname) empty($varname) Error checking with die Arrays Not really arrays indexed by key, which can be string not always the same type foreach ($array as $item) foreach($array as $key => $value) Cookies setcookie(...) $_COOKIE Session variables $_SESSION Needs cookies Loops while loops for loops foreach($array as $value) foreach($array as $index => $value) Functions default arguments function foo($name = "Default Name") (not much in 2022) Objects __construct __tostring $this->thing $this->method() vs method() class vs local vs global variables print_r header("location: ...") Variables global superglobal $_REQUEST $_COOKIE $_POST $_GET Databases Know some way to fetch data like http://euclid.nmu.edu/~rappleto/Classes/CS465/PHP/Databases/Database_Example_Object.php.txt real_escape_string Error checking Files (not in 2022) Open a file Read a file Write a file See if the file exists File Uploads See https://www.php.net/manual/en/features.file-upload.post-method.php Multi layer architecture Regular Expressions end of line chars ^ and $ Repeat chars * and + Maybe char ? Sets of chars [abc] and [^abc] Ranges of chars [a-z] Special sets like /s and /S modifiers like “/steve/i” Regular Expression PHP Methods preg_match and preg_match_all preg_replace preg_split Python Know basic python syntax Know there is a 3.X and a 2.X Know how to make a functions With default parameters Know how to make an object Self is your friend Self is really your friend List Ordered, duplicates allowed http://euclid.nmu.edu/~rappleto/Classes/CS295.Python/list_quiz_answers.py Make a list l = [] l = [1,2,3] Lists in lists l = [1,2,[3,4,5]] print(l[2][1]) Length of a list len(l) Slices l[0:2] -- Items 0 and 1 but not 2 l[3:] -- Items from 3 to the end l[:3] -- Items 0,1,and 2 l[-4] -- Forth item FROM THE END l[-4:-2] -- Some items near the end Item existance if "fred" in words: Appending l.append("apple") l.append(["pear", "orange"]) -- adds ONE item to the list Removing from a list l.remove("pear") l.pop() -- remove the last item del l[2] Sorting a list l.sort() Reversing a list l.reverse() My favorite l.shuffle() Set (Only a little bit) No duplicates No order (so no sort, shuffle, etc) Making a set s = {"apple", "bananna"} s = set((1,2,3)) -- double parenthesis! s = {} -- makes a dictionary not a set!!! Adding an item s.add("pear") Check Membership if "pear" in s: Remove from a set s.remove("pear") Array Use a list Tuple (only a little bit) Like a read only list So no add, remove, shuffle, t = (1,2,3,4) Dictionary Like a list with strings as indexes Order is weird d = {"Randy":52, "Scott":41} For loops for key, value in d.items(): String s = "Dead Parrot" works almost like a list with for loops, slices, etc. Control Structures And is spelled either "and" or "&&" Or is spelled either "or" or "||" For loop for num in range(4): -- does 0,1,2,3 for num in range(2,5): -- does 2,3,4 for num in range(2,22,3): -- does 2,5,8,11,14,17,21 for num in range(len(l)): -- sometimes what you want for item in l -- other times what you want for key, value in d.items(): -- iterate thru a dictionary While loop while x < 3: If statement if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b") Python functions def fred(x): return x+4 y = fred(17) # with a default value def wilma(x = 3): return x + 4 z0 = wilma() z1 = wilma(2) Math Normal with normal order of operation 5//2 -- integer division yield 2 not 2.5 5**2 -- power yields 25 x++ -- There is no ++, but there is x+=1 PIP (Just that it exists) The Python installer program Uses a library of modules stored "in the cloud" pip3 install thing -- on the command line Flask Example from flask import route, run @route('/hello') def hello(): return "Hello World!" run(host='0.0.0.0', port=8080, debug=True) Other examples return static_file(filename, root='/path/to/your/static/files') @route('/show/') @route('/object/') Google Pagerank have lots of important people point to you then win $$$$ Data Structures File Stuff for name in os.listdir("/home/fred"): file = open("fred.txt", "r") glob Other file stuff Routes Can have method= for just post or just get Can have URL pattern matching @app.route('/hello/') def index(): return render_template(‘hello.html’,name = user) Templates Can pass in variables. Have their own if {% if marks>50 %}

Your result is pass!

{% else %}

Your result is fail

{% endif %} Have their own for loop {% for key, value in result.iteritems() %} {% endfor %}
{{ key }} {{ value }}
AJAX Know how to Multi layer architecture