<?php
// script 태그 사이에 코드를 작성하는게 특이점
?>
sudo sudircd ../cdviesc + : + qV : visual 모드, ese 누르면 원대래도 돌아옴I : 입력모드, 이 때 작성하면 댐Shift+: + wq (또는 w)esc+d+d : 해당 줄 삭제리눅스는 자동 업데이트가 없기 때문에 우리가 일일히 업데이트 해줘야 함
1) sudo apt update : 패키지 목록을 업데이트하여 최신 버전의 소프트웨어 정보를 가져옴
2) sudo apt install php -y : php 설치 & 모든 확인 메시지에 자동으로 'yes' 응답
3) sudo apt install libapache2-mod-php : php와 apache2 웹서버 연동을 위한 모듈 설치
4) sudo systemctl restart apache2 : 재접속해서 변경내용 적용(서버 껏다 켬)
1) vi HelloPHP.php : php 파일 만들기
2) <?php?> : 태그 만들어주기
3) echo
<?php
echo "Hello, World!";
?>
4) 접근해보기 : ip주소 + 파일이름

[22:00]
WebserverManager
public static IEnumerator GetWWWData(string _path, Dictionary<string, string> Fields, Action<string> OutAction)
{
WWWForm form = new WWWForm();
foreach (string key in Fields.Keys)
form.AddField(key, Fields[key]);
using (UnityWebRequest www = UnityWebRequest.Post(_path, form)
{
yield return www.SendWebRequest();
if(www.result == UnityWebRequest.Result.ConnectionError ||
www.result == UnityWebRequest.Result.ProtocolError ||
www.result == UnityWebRequest.Result.DataProcessingError)
{
OutAction?.Invoke(www.error);
}
else
{
string str = www.downloadHandler.text;
str = str.Replace("<br>", System.Environment.NewLine);
str = str.TrimEnd('\n');
OutAction?.Invoke(str);
}
}
}
1) vi + 파일명.php : 파일 하나 새로 파기
2) i : Insert 모드
3) <?php ?> php 태그 넣기
4) 저장
<?php
$number = $_POST['number'];
$result = $number*10;
echo "The result is : ".$result;
?>
$ : php에서 변수를 부르거나 설정할 때 사용, PHP의 근본이자 마스코트 같은 아이 ㅋ$_POST : 이 때 사용하는 것['number'] : 큰따옴표 사용해도 ㄱㅊ,WebServerObject
public class WebServerObject : MonoBehaviour
{
Dictionary<string, string> keys = new Dictionary<string, string>();
void Start()
{
keys.Add("number","5");
StartCoroutine(WebServerManager.GetWWWData("주소/파일명.php", keys, GetString));
}
void GetString(string)
{
Debu.Log(str);
}
}
{
"name":"John",
"age":30,
"adress":{
"street":"123MainSt",
"city":"Anytown"
}
}
Newtonsoft.JsonPackage
string json = JsonConvert.SerializeObject(person);
com.unity.nuget.newtonsoft-json@3.0 복사@3.0은 빼고 복붙ㄱㄱHuman
public class Human
{
public string name;
public int age;
public bool isStudent;
public Adress adress;
}
Adress
public class Adress
{
public string street;
public string city;
}
WebServerObject
public class WebServerObject : MonoBehaviour
{
Human human;
void Start()
{
human = new Human();
human.adress = new Adress();
human.name = "John";
human.age = 30;
human.isStudent = false;
human.adress.street = "123MainSt";
human.adress.city = "Anytown";
// 클래스 => 문자열
string json = JsonConvert.SerializeObject(human);
Debug.Lob(json);
}
}
public class WebServerObject : MonoBehaviour
{
Dictionary<string,string> humanDic = new Dictionary<string,string>();
void Start()
{
humanDic.Add("John", json);
StartCoroutine(WebServerManager.GetWWWData("주소/파일이름.php", humanDic, GetString));
}
}
sudo sucd ../../var/www/htmlvi 파일이름.phprm : 잘못 저장한거 지우기rm FIRTSTPHP.php<?php
// John의 문자열 데이터
$json_data = $_POST('John');
// JSON 데이터를 PHP 배열로 변환 ( 문자열 => 클래스 ), 문자열 배열 사용할 것인지
// JSON 문자열 데이터를 data라는 변수 안에 넣어줌
$data = json_decode($json_data, true);
// 변환된 데이터 출력(key값을 넣고 해당 값을 가져욤);
echo "Name : " . $data['name'] . "\n";
echo "Age : " . $data['age'] . "\n";
echo "Is Student : " . ($data['isStudent'] ? 'Yes' : 'No') . "\n";
echo "Street : " . $data['address']['city'];
?>
"\n" : 줄바꿈 , 개행
. : 문자열 더할때 +를 여기선 .으로 씀
정리 2
1 플레이어 데이터를 클래스 하나로 모은 다음에
2 플레이어 데이터를 JSON CONVERTER를 사용해서 문자열로 변환
3 그걸 웹서버로(POST) 받아와서 정리
4 My SQL



신규 서버 생성
웹서버 설치
PHP연동
ex) 데이터가 들어왔을 때 , 뭐가 뭐뭐인지 확인하고 뭐가 뭐뭐가 아닐때 서버에서 처리를 해라
랭킹 같은 경우엔