관리 메뉴

Silver Library (Archived)

PHP 레거시 코드를 react 로 변환 한다면? 본문

Face the fear, build the future/Library of Logging

PHP 레거시 코드를 react 로 변환 한다면?

Chesed Kim 2022. 12. 24. 21:42
반응형

가령, 만약 PHP 레거시 코드를 react 라이브러리로 리모델링 한다면?

이런 사례가 있지 않나 해서 알아보니 역시 '있었다' 라는 결론입니다.

 

지금은 혹시 도움될 지 몰라 알아둔 스크랩 형태에 불과하지만, 알아 둔 내용을 요약을 하자면:

1. 만약 authentication 과 같은 보안 부문일 경우, react 에서 context 형태로서도 대응이 가능해 보임.

예를들어...

<?php
    session_start();
    if(isset($_SESSION['client'])){
        echo 1;
    }
?>

라는 PHP 코드를, 아래와 같이 react 로 변환하면:

import { useState } from "react";

function App() {
    const [session, setSession] = useState(false)

    const loginToggler = async (username,password) => {
        // Some Fetch with api and check the username and password and get the response of true or false
        const res = !session // const res = await fetch("http://localhost:5000/users", ....
        setSession(res)
    }
    return (
        <div>
            {session ? "You are logged in ":"You aren't logged in "}
            {!session ? <button onClick={loginToggler}>Login</button>:<button onClick={loginToggler}>Logout</button>}
        </div>
    );
}

export default App;

이런 식으로도 옮길 수 있으나, 보안이 괜찮은지? 에 대한 질문글이었다. 

결론부터 적자면 state management 인 useState 라 해서 보안에 결함이 있는 건 아니라는 점.

다만, context 로 하는 편이 좀 더 권장된다는 의미로 보여진다.

 

그렇다면 Redux로도 적용이 가능 하다는 결론이 나오는데. 뭐, 지금은 이 정도로 개요만 알아두고 글을 마치겠습니다.

 

convert php session to react

I trying to make a secure react login system but I not sure how do I have to do it so I thought this might work if I ask this question. I want to convert this simple PHP code to react : <?php

stackoverflow.com

 

Converted a website from PHP to ReactJS and moved the hosting from AWS EC2 to AWS S3

My Free Tier with AWS is over and I was already paying a few bucks just to host a small static website in AWS EC2. I could have just…

medium.com