PHP - 没有数据库存储信息 [英] PHP - Store information with NO database

查看:254
本文介绍了PHP - 没有数据库存储信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要提高在Apache和PHP网站具有页面包含的文件列表的表格。我的目标是允许用户设置这些文件作为&ldquo之一;重要”的一个是基于一些具体和主观标准。为了做到这一点,我想存储有关的最&ldquo信息;重要”的文件中的某些方式,与我能够既不使用也不数据库文件的限制(按上级规定的限制的)。

I am going to improve a web site in Apache and PHP which has a page with a table containing a list of files. My goal is to allow the user to set one of those files as the “important” one based on some specific and subjective criteria. In order to do that, I want to store the information regarding the most “important” file in some way, with the restriction that I am able to use neither databases nor files (constraints imposed by supervisor).

我的问题是:


  • 这可能吗?

  • 我怎样才能做到这一点?

我已经没有在这个网站进行搜索,但我没有找到答案。

I already did a search in this site, but I did not find an answer.

编辑:顺便说一句,最后我用一个XML文件,解决了我的问题。非常感谢大家。

By the way, finally I solved my problem using an XML file. Thanks a lot to everyone.

推荐答案

假设这些标准都是客户端,而不是服务器端,因为如果他们是服务器端,它应该是一个重要文件所有的用户,那么有没有办法做到这一点没有储存。

Assuming these criteria are client-side rather than server-side, because if they're server-side and it's supposed to be one 'important' file for all users then there's no way to do this without storage.

的应该回答您的解决方案是localStorage的()...

它的JavaScript相关的,绝对不是一个完美的解决方案,但 HTML5的localStorage 允许你存储$ P $在用户计算机pferences。

It's Javascript dependent and definitely not a perfect solution, but HTML5 localStorage allows you to store preferences on your users' computers.

首先,检测为localStorage的()的支持:

First, detect support for localStorage():

if (Modernizr.localstorage) { // with Modernizr
if (typeof(localStorage) != 'undefined' ) { // Without Modernizr

然后设置参数如果支持:

Then set a parameter if it's supported:

localStorage.setItem("somePreference", "Some Value");

再后来检索,只要您的用户尚未清除本地存储的:

And then later retrieve it, as long as your user hasn't cleared local storage out:

var somePreference = localStorage.getItem("somePreference");

当你想清楚,只需要使用:

When you want to clear it, just use:

localStorage.removeItem("somePreference");

有关使用不支持(以上)的浏览器,你可以使用本地存储黑客滥用的Flash本地共享对象,但这些绝对不是理想的。

For those using unsupported (older) browsers, you can use local storage hacks abusing Flash LSOs, but those are definitely not ideal.

有关会话或饼干什么?

这两者都是存储的故意临时形式。即使闪光灯本地共享对象比cookie用于长期储存好。

Both of these are intentionally temporary forms of storage. Even Flash LSOs are better than cookies for long-term storage.

约束是字面上鼓励穷人的做法...

所有这些选项是浏览器端。如果用户移动到另一台PC,他/她的preferences将是PC上的数据库驱动的认证系统,您可以节省preferences对登录复位,不像。

All of these options are browser-side. If the user moves to another PC, his/her preferences will be reset on that PC, unlike with a database-powered authentication system where you can save preferences against a login.

存储这种数据的最佳方式是在数据库中。如果无法运行数据库的服务,您可以使用 SQLite的或存储在JSON或XML文件中的数据。

The best way to store this kind of data is in a database. If you can't run a database service, you could use SQLite or store the data in JSON or XML files.

这篇关于PHP - 没有数据库存储信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆