php
-
http 헤더 추가하기php 2023. 9. 8. 08:44
header() 함수는 PHP 인터프리터가 브라우저로 보내는 HTTP 헤더를 업데이트 한다. 1. Location members Area Welcome to the members area location 헤더를 사용하면 새로운 URL로 사용자를 보낼 수 있따. PHP 인터프리터가 이후의 PHP 코드를 실행하지 못 하도록 exit 명령어를 사용해야한다. 2. Content-type 대부분의 php 파일은 브라우저로 보낼 html을 생성하지만, php는 json , xml , css와 같은 유형의 파일을 생성하는 데 사용할 수 있다. header('Content-type: application/json'); 3. Cache-Control 브라우저는 사용자가 본 페이지를 캐시(저장)할 수 있다. 만약에 그 페..
-
Class .. Staticphp 2023. 9. 6. 16:13
1. Static 으로 선언할 경우. Class 내부에서 Static으로 선언된 변수 / 메서드의 경우. 객체에 소속되는 것이 아니라 클래스에 고정되어 있다. -> Static이 선언된 요소는 클래스를 가져오기만 해도 메모리에 고정적으로 할당된다. 따라서, 인스턴스를 통해 객체를 생성하지 않아도 이용이 가능하다. 클래스를 불러오는 프로그램이 실행되면 자동으로 메모리에 static이 적재되고, 프로그램이 종료될 때 해제된다. ** 결국 Static은 사용자가 객체를 인스턴스하기 전 부터 올라가 있기 때문에, Static 요소 내부에서는 인스턴스 변수를 활용할 수 없다. ** 일반적인 요소의 경우, 객체를 생성하면 메모리의 Heap 영역에 올라간다. Heap 영역에 올라간 요소들은 Garbage Collec..
-
Classphp 2023. 9. 6. 09:07
php에서 클래스(객체)를 생성하고 선언하는 방법을 알아보자 class Account{ public int $number; public string $type; public float $balance; public function __construct($number, $type, $balance) { $this->number = $number; $this->type = $type; $this->balance = $balance; } public function deposit(float $amount): float { } public function withdraw(float $amount): float { } } 1. 객체 인스턴스 $account = new Account; $account2 = nes ..
-
지정인수php 2023. 9. 6. 08:30
PHP 8 에서 인수 앞에 매개변수 이름을 넣을 수 있다 만일 지정인수가 없다면 function( 3 , 5, 0 , 19 ); 와 같이 매개변수에 값을 넣지 않는 부분에도 0 을 꼭 넣어줘야한다 하지만 지정인수를 설정하면 순서에 상관없이 매개변수를 이용할 수 있다 public function calulate($cost , $quantity, $discount = 0 , $tax = 0){ } 위와같이 함수가 선언되었다면, calulate(5 , 10 , tax : 3); 또는 calulate(quantity : 7 , cost : 4 , tax : 10 ) 원하는 방법대로 함수를 호출할 수 있다
-
전역 / 정적 / 옵셔널 변수php 2023. 9. 4. 08:42
1. 전역변수 global $cost; 전역 범위에서, 변수에 저장된 값에 접근하거나 업데이트 할 수 있다 다른 프로젝트에서 봐야할 경우 위와 같이 선언한다. 2. 정적변수 static $value = 10; 일반적으로 함수 내에서 선언된 변수는 함수가 끝나면 삭제된다. 정적변수로 선언할 경우, 함수가 끝나도 변수를 삭제하지 않고 기억한다. 다만, 함수 내에서 선언되었기 때문에, 함수 내부의 코드에서만 사용할 수 있다. 3. 옵셔널 매개변수 php에서는 JAVA와 달리 오버로딩이 불가능하다. 그래서 함수에 매개변수가 선언되어 있다면, 함수를 호출할 때 항상 동일한 수의 매개변수가 필요하다. 하지만 옵셔널 매개변수를 활용하면, 해당 변수로 지정된 매개변수 없이 함수가 호출 된 경우 default 값을 가진..
-
워드프레스 페이지 추가php 2023. 9. 1. 12:11
서버에 올라가있는 프로젝트를 다운받고 숏코드를 활용해서 워드프레스 페이지를 추가해보자 1. 서버에 접속해서 관리자 권한으로 원하는 파일을 압축하자 ssh 서버명 sudo -s cd data/htdoc 위의 명령어로 프로젝트 파일이 있는 장소로 이동 후 tar cvf fileName.tar fileName tar을 이용해서 원하는 프로젝트를 압축한다. 2. filezilla를 활용해서 압축 된 파일을 로컬로 가져온다. 이 때, 서버의 host 계정이 필요하다 ip는 .ssh의 config 를 참조하자 3. 코드 변경 후 upload 될 수 있게 sftp.json을 수정해준다 4. FMS 에서 컨설팅 관리 -> 컨설팅을 등록 -> 설문 등록 DB에 페이지에서 나타내고싶은 데이터를 저장한다. 5. 워드프레스 ..