简体   繁体   English

是否有可能在php中保存在网页上所做的更改而无需发送到数据库中

[英]is it possible in php to save changes made on web page without sending into database

I have done some research on this topic but couldn't come up with a solution. 我已经对此主题进行了一些研究,但无法提出解决方案。

Is it possible in php to save changes made on web page without sending the infos into database??I'm giving each user the ability to make some changes on their pages and after changes made,every visitor of that page would be able to see the new edited text. 是否有可能在php中保存在网页上所做的更改而无需将信息发送到数据库中?我使每个用户都可以在其页面上进行某些更改,更改后,该页面的每个访问者都可以看到新的编辑文本。

How can I do that? 我怎样才能做到这一点?

Here is the sample php code 这是示例PHP代码

<?php

  if(isset($_POST['x']) && isset($_POST['hi'])){
   $hel=$_POST['hi'];
  }
 else{
   $hel="Hello There";
  }

?> 

HTML Part HTML部分

<form id='sub' name='sub' method='post' action='edit.php' enctype='multipart/form-data'>
 <input type='text' id='hi' name='hi'>
 <input type='submit' id='x' name='x' value='publish'>
</form>
<?php echo $hel;?>

Thanks in advance. 提前致谢。

No,It is not possible.That is what database for.Use database to store the changes,because that is the easiest and best way to do it. 不,这是不可能的。这就是database用途。使用database存储更改,因为这是最简单,最佳的方法。

Or you can store it as a file as well.This link might be useful,if you are not familiar with file handling . 或者,您也可以将其存储为file 。如果您不熟悉file handling ,则此链接可能很有用。

http://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete http://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete

Yet again,using database is better choice. 再一次,使用database是更好的选择。

You have to save it somewhere in permanent storage. 您必须将其保存在永久存储中的某个位置。 You get to choose - either a database or file. 您可以选择-数据库还是文件。 So if you don't want to store it in a DB, then store it in a file. 因此,如果您不想将其存储在数据库中,则将其存储在文件中。

However when your data becomes complex and you want to link data to each other, you really need to go to a database. 但是,当数据变得复杂并且想要将数据彼此链接时,您确实需要进入数据库。

Probably not what you're asking, but you can save data until you close the browser using sessions. 可能不是您要的内容,但是可以保存数据,直到使用会话关闭浏览器为止。

Start your script with: 使用以下命令启动脚本:

<?php
session_start();

Then, save data inside $_SESSION : 然后,将数据保存在$_SESSION

$_SESSION['x'] = 'Whatever';
$_SESSION['hi'] = 'Great!';

Everything inside $_SESSION will stay even if you reload the page, until you close the browser. 即使重新加载页面,$ _ SESSION内的所有内容仍将保留,直到关闭浏览器。

If not, write bunch of JSON files to the filesystem. 如果不是,则将一堆JSON文件写入文件系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM