PHP의 원리
Browser -> WebServer PHP
*.html <-> webServer
*.php <-> webServer <-> php
PHP의 데이터 타입
numeric
<?php
$a = 123; // decimal number
var_dump($a);
echo "<br>";
$b = -123; // a negative number
var_dump($b);
echo "<br>";
$c = 0x1A; // hexadecimal number
var_dump($c);
echo "<br>";
$d = 0123; // octal number
var_dump($d);
?>
string
<?php
$a = 'Hello world!';
echo $a;
echo "<br>";
$b = "Hello world!";
echo $b;
echo "<br>";
$c = 'Stay here, I\'ll be back.';
echo $c;
?>
concatenation operator
<?php
echo "Hello "."world";
?>
PHP의 변수
$
PHP의 URL 파라미터
index.php?name=ss.park
php파일에 name변수에 ss.park을 전달해준다.
url에서 넘어온 name(echo $_GET['name'];)
url
index.php?name=ss.park&address=서울
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
안녕하세요. <?php echo $_GET['address']; ?>에 사시는 <?php echo $_GET['name']; ?>님
</body>
</html>
PHP의 조건문 활용
isset — Determine if a variable is declared and is different than NULL
isset ( mixed $var [, mixed $... ] ) : bool
Determine if a variable is considered set, this means if a variable is declared and is different than NULL.
If a variable has been unset with the unset() function, it is no longer considered to be set.
isset() will return FALSE when checking a variable that has been assigned to NULL. Also note that a null character ("\0") is not equivalent to the PHP NULL constant.
If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are considered set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.
PHP에서 FORM과 POST
서버로 데이터를 전송할 때 사용하는 HTML의 기능인 form을 살펴봅니다.
URL을 통하지 않고 은밀하게 데이터를 전송하는 방법인 POST 방식
- Form : 사용자가 입력한 정보를 URL 파라메터로 만들어내는 기계
<form action="action.php" method="get/post"> 로 보내면 $_POST['title'] 로 사용한다.
get은 Bookmark용도로 적합하다. $_GET
post은 Bookmark용도로 적합하다. $_POST
Redirection
header('Locaction: /index.hp?id=".$_POST['title'];