How to do it correctly?

Hello Kirupa! I started learning Php not long ago and I want to combine Php and React, but I don’t know how it would be more correct to do it.

  1. At the beginning, make a project in React and make an Api in php

  2. Do everything in php and connect React libraries and do everything there

  3. If I do it first on React and make the Api in php, how can I make the api available only through the site

I’m still a newbie and I don’t fumble, I can ask stupid questions :slight_smile:

I want to make a Vk Mini App under the Vk interface, and there it is necessary to use React components, I would take the first option, but I still want to somehow protect the Api from hacking and DDoS attacks.

But I asked other questions so that it would be clearer to me how it would be better to do.

I hope you will help me, because it’s all difficult for me, but you have experience and I think you will answer me.

Thanks for the answer in advance!

Well, or if others also answer me, thank them too for their help!

If you are starting from scratch and using React, I would suggest you use Next.js:

This uses React-JavaScript for both the client-side as well as on the server via Node. This is the most modern way to use React to build these “fullstack” apps where frontend and backend is handled nicely by the framework.

If you really do want to use PHP, note that PHP is fully a server-side language. You would use React for all client-side activities and PHP would be used to process anything that needs to only be done on the server. An API driven approach, what you suggest as Option #1 would be my preferred vote. To keep the API private to only your site, that’s where CORS comes in. I wouldn’t worry about that for now, but note that it is totally doable to keep others from calling your API :slight_smile:


1 Like