使用WhizBase为注册用户创建登录系统

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles about WhizBase).

本教程将讨论使用WhizBase的登录过程。 在本文中,我假设您已经了解HTML。 我将使用WhizBase Server Pages编写代码,因此您需要了解WBSP的一些基础知识(您可能会参考其他有关WhizBase的文章)。

In the last article "Create an AJAX supported registration form with WhizBase" I have explained how we can make a registration process, now when users register to your site, you need to make them log-in to secured pages.

在上一篇文章“使用WhizBase创建AJAX支持的注册表单”中,我解释了如何进行注册过程,现在,当用户注册到您的站点时,您需要使他们登录到安全页面。

The Log-in Page

登录页面

I will create a log-in page which is a simple HTML code and save it as "login.ic", I will explain later why I did not save it as HTML.

我将创建一个简单HTML代码登录页面,并将其另存为“ login.ic”,稍后我将解释为什么我没有将其另存为HTML。

<html>
<head></head>
<body>
         <form action="login.wbsp" method="post">
          Please enter your log-in information:<br />
          Username <input type="text" name="username" /><br />
          Password <input type="password" name="password" /><br />
          <input type="submit" value="Login" />
          </form>
</body>
</html>

I will not explain this code, it is a simple HTML code with to fields and a submit button.

我不会解释此代码,它是一个简单HTML代码,其中包含to字段和一个Submit按钮。

The secured page

安全页面

I will create a page where its data must not be seen by non-registered users, I will save it as "secured.ic", again I am saving it with IC extension, I will explain that later.

我将创建一个页面,未经注册的用户不得查看其数据,将其另存为“ secured.ic”,再次使用IC扩展名进行保存,稍后将进行解释。

<html>
<head></head>
<body>
Hello $wbgets[username],<br />
you are logged in!
</body>
</html>

In this code we have just one new function, it is the $wbgets[] which is a function to get the session variable "username" where the username is stored.

在此代码中,我们只有一个新函数,它是$ wbgets [],该函数用于获取存储用户名的会话变量“ username”。

What to show?

显示什么?

This is my main page where I will check if the visitor is logged in or not, if yes I will show him the secured page, if not I will show the log-in form. Here we will discuss sessions in WhizBase. Please use WhizBase 6, because sessions are not used in earlier versions.

这是我的主页,我将在其中检查访问者是否已登录,如果是,我将向他显示安全页面,如果不是,我将显示登录表单。 在这里,我们将讨论WhizBase中的会话。 请使用WhizBase 6,因为早期版本未使用会话。

[FormFields]
WB_UseSessions=T 
#* Use sessions in this page *#
<!--WB_BeginTemplate-->
$wbif["$wbgets[logged]"="1"| #* check if we have a session variable logged and have a value 1 *#
$wbrinc[secured.ic] #* if yes, show the secured page, the user is logged in *#
|
$wbrinc[login.ic] #* if not, show the log-in form, the user is not logged in *#
]

As you can see from comments in the code I have turned the sessions on by putting WB_UseSessions=T in the Form-Fields section, so WhizBase will start processing session data. Sessions are not included in WhizBase by default, so you need to turn it on in every page you use them in.

从代码注释中可以看到,我通过在Form-Fields部分中放置WB_UseSessions = T来打开会话,因此WhizBase将开始处理会话数据。 默认情况下,会话不包含在WhizBase中,因此您需要在使用会话的每个页面中将其打开。

Next, I am testing if there is a session variable "logged" with value "1" by an if statement, this variable will be set in the file "login.wbsp", I will explain that in the next section. Now just consider that we have a session variable "logged" with value "1" if we are logged in and nothing if we are not.

接下来,我将通过if语句测试会话变量“ logged”的值是否为“ 1”,该变量将在文件“ login.wbsp”中设置,我将在下一部分中进行解释。 现在,只需考虑如果我们已登录,我们就有一个会话变量“ logged”,其值为“ 1”,否则,则没有任何内容。

Now why I have saved two files with "IC" extension, it is because in WhizBase I can tell the server not to interpret files with "IC" extension if it is called directly, these files can only be called with-in a WhizBase file by $wbrinc or $wbinc. This process is called including files. In this case I am using $wbrinc because I do not want to render the file until it is needed. In my case I have two files "secure.ic and login.ic", so I will render one of them only. $wbinc would include and render both files and that takes more resources. You can check the differences between these two functions in the help file of WhizBase.

现在为什么要保存两个扩展名为“ IC”的文件,这是因为在WhizBase中,我可以告诉服务器不要直接调用扩展名为“ IC”的文件,这些文件只能在WhizBase文件中调用通过$ wbrinc或$ wbinc。 此过程称为包含文件。 在这种情况下,我使用$ wbrinc是因为我不想在需要它之前渲染文件。 在我的情况下,我有两个文件“ secure.ic和login.ic”,因此我将仅渲染其中一个。 $ wbinc将包括并呈现两个文件,这将占用更多资源。 您可以在WhizBase的帮助文件中检查这两个功能之间的差异。

If yes, which is if the session variable "logged" have a value "1" the user is logged in, so I will show him the content of "secured.ic", if not I will show him the content of "login.ic".

如果是,即会话变量“ logged”的值是“ 1”,则用户已登录,因此我将向他显示“ secured.ic”的内容,否则,我将向他显示“ login”的内容。我知道了”。

Finally save this file as "default.wbsp", this is just a one file example, if you have more than one page you rather use a DB than "IC" files.

最后将此文件另存为“ default.wbsp”,这只是一个文件示例,如果您有多个页面,则宁愿使用DB而不是“ IC”文件。

Log-in process

登录过程

In this file I will check if the username and the password the visitor provided do match with the data in the DB. I will use the DB I have created in my last article "Create an AJAX supported registration form with WhizBase".

在此文件中,我将检查访问者提供的用户名和密码是否与数据库中的数据匹配。 我将使用在上一篇文章“使用WhizBase创建AJAX支持的注册表单”中创建的数据库。

[FormFields]
WB_UseSessions=T 
#* We need sessions *#
WB_command=Q 
#* Query the DB *#
WB_BaseName=reg.mdb 
#* connect to red.mdb DB file*#
WB_RcdSet=profile 
#* use profile table for our query*#
WB_Query=username='$wbv{username}' and password='$wbv{password}' 
#* get all records which have this username and this password in the same time *#
WB_MaxRec=1 
#* one record is enough *#
[MsgAndLbl]
WBM_NoMatch=$empty$
<!--WB_BeginTemplate-->
<html>
<head></head>
<body>
$wbif[$wbp[RC]=1| #* if we have match we will have one record *#
   $wbsets[logged|1|f] #* set logged as 1 *#
   $wbsets[username|$wbv[username]|f] #* set username with the username provided *#
   You have been successfully logged in, please click <a href="default.wbsp">here</a> to return to your page.
|
   Your username and password does not match, please go back and try again!
]
</body></html>

In this file I will use sessions, I need to set the session variable "logged" as "1" if the user provides true data. Here I am querying the DB looking for a match, I need just one record with the provided username and password. One record is enough because there is no two users with the same username.

在此文件中,我将使用会话,如果用户提供了真实数据,则需要将会话变量“ logged”设置为“ 1”。 在这里,我正在查询数据库以查找匹配项,我只需要一条带有提供的用户名和密码的记录。 一条记录就足够了,因为没有两个用户使用相同的用户名。

I am using $wbp[RC] to return number of records returned by the query, I can get one record or no records, If there is one record then it is a match and the session variable "logged" is set to "1", I will also set the session variable "username" with the username provided.

我正在使用$ wbp [RC]返回查询返回的记录数,我可以得到一条记录,也可以没有记录,如果有一条记录,则表示匹配,会话变量“ logged”设置为“ 1” ,我还将使用提供的用户名设置会话变量“ username”。

In case I do not have a match, simply give an error message.

如果我没有匹配项,只需给出一条错误消息。

For more information email me at: NurAzije [at] Gmail [dot] com Or visit the WhizBase official site at www.whizbase.com

有关更多信息,请给我发送电子邮件:NurAzije [在] Gmail [点] com或访问WhizBase官方网站,网址为www.whizbase.com。

NurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.

NurAzije是一名PHP和WhizBase程序员,在撰写本文时,他正在与WhizBase合作进行多个项目。

翻译自: https://www.experts-exchange.com/articles/2909/Create-a-log-in-system-for-registered-users-with-WhizBase.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值