I'm making a collaborative editor for websites, much like Google Docs, but it's built for coding and development. I want to allow multiple users to edit a file at the same time, and push their changes both to the server and the other person viewing the file. How could I do this?
I can't figure out how to synchronize the data between users. The code I have right now is as follows:
AJAX in JS:
function update(f, txt){
$.ajax({
type: 'POST',
data: {text: txt, file: f},
url: "save.php",
});
}
save.php:
$file = $_POST['file'];
$contents = $_POST['text'];
file_put_contents(dirname(__FILE__) . "/preview" . "/" . $file,$contents);