생활코딩 웹 어플리케이션 만들기 노트
1. PHP 환경 설정 변경
Find php.ini, open it, and ctrl + F to find "display_errors" and do modifications as follows:
change from:
display_errors = Off,
to:
display_errors = On
why is it turned off as default?
a possible attacker can see all vulnerabilities when it's on.
Find opcache and set opcache.enable as 0.
This will allow the software to reflect the changes in php files immediately.
Open bitnami and restart apache to reflect the modifications made.
2. Javascript vs PHP
3. 웹페이지에 JS&PHP 코드 삽입하기
Find php.ini, open it, and ctrl + F to find "display_errors" and do modifications as follows:
change from:
display_errors = Off,
to:
display_errors = On
why is it turned off as default?
a possible attacker can see all vulnerabilities when it's on.
Find opcache and set opcache.enable as 0.
This will allow the software to reflect the changes in php files immediately.
Open bitnami and restart apache to reflect the modifications made.
2. Javascript vs PHP
- Javascript may be able to do things that PHP cannot, and vice versa. But on the other hand, they may have complementing functions for each other.
- HTML & CSS are static languages. But JS and PHP are dynamic languages. This means they can interact with the user.
- What you could usually do with JS: Make something happen that didn't when a webpage loaded with HTML and CSS
- What you could usually do with PHP: Express different pieces of information with one single HTML (you could change some information on one HTML, for example a nav, and you do not have to change that on another HTML that also has the same nav. Instead, you only change .php and that's it)? And you can open ~.php to view in a web browser.
3. 웹페이지에 JS&PHP 코드 삽입하기
- Basically, .php behaves the same as .html (but .html does not behave the same as .php, of course).
- To create and make changes to a .php file, do so at /mampstack-.../apache2/htdocs/
- For my laptop, I set the port for apache at 8079, so when I need to view a file that is located in:/mampstack-.../apache2/htdocs/phpjs/1.php: I need to type into the address bar of my browser: http://localhost:8079/phpjs/1.php (of course with the server on my computer turned on)
Inserting php code to format together with html
|
Inserting JS code to format together with html
|
- The difference between .php and .js is that php is a server-side language, so "hi" and 10+10 are handled already (by the php engine/interpreter) before the webpage gets loaded to be shown, but JS is a client-side language that the web browser interprets and brings out the result to us. Therefore, the source code viewed on the browser will also be different, even though these two examples produce exactly the same results:
Source code for above php code viewed on a web browser
|
Source code for above JS code viewed on a web browser
|
4. Datatypes and operators
- Expressing strings: embrace them with double quotes, like: "this"
- In JS, when you need to combine strings, do: "combine"+"these"+"together". Same for numbers: "20" + "20" will give you "2020".
- In PHP, do the same for strings containing letters, but for numbers, "20"."20" will give you "2020". "20"+"20" will give you 40 in contrast.
5. Debugging
- Go .../mampstack.../apache2/logs/error.log. The lowest error message contains the most recent error.
6. Variables
- Variable means 'subject to change'.
- Variable declaration in JS: name = "myName";
- Variable declaration in PHP: $name = "myName";
7. Comparisons
- You know the basics if you are not new to programming.
8. Conditional statements
- if-else construct is just as you expect it to be.
9. A very simple login function
- Know that PHP files can transfer information to one another through form tag.
JS
|
loginScreen.php
login.php
|
for .php, when the user clicks on the submit button, the web browser will open the file specified as a value in action attribute (in the example above, "login.php") and, the address of that webpage will be: [the value specified for action attribute][?][value of name attribute in input tag=][the value typed in by the user]. And of course, according to the user input, the page is going to show either of the two messages.
10. while loops
- It's just as you expect them to be. Pass.
11. Arrays(declaration and access operators) and while loop
- JS: array = new Array("1", "2"); document.write(list[0]);
- PHP: array = new Array("1", "2"); echo $list[0];
Example from 생활코딩
12. Functions
- The syntax might just be a little bit different from what you learned from c++ or java, because php and js do not seem to provide return types for functions
- JS: (declare) function functionName(input){ return input+1;} (call) document.write(functionName(1));
- PHP: (declare) function functionName($input) {return $input+1;} (call) echo functionName(1);