在HTML页面上显示PHP表单帖子输出

时间:2022-10-16 12:49:08

I'm making an online quiz using AJAX. I've made a registration form for a user to input their details, and the php file returns a username if the details are valid. I'm trying to figure out how to go straight to the main quiz page once the form POST works and be able to display the given username on that main page where I will be using another php file to display the quiz questions. Also I'm using a sample php file for the username return and am unable to view or change anything in that.

我正在使用AJAX进行在线测验。我已经为用户输入了一个注册表单来输入他们的详细信息,如果细节有效,php文件会返回一个用户名。我试图弄清楚如何在表单POST工作后直接进入主测验页面,并能够在该主页面上显示给定的用户名,我将使用另一个php文件来显示测验问题。此外,我正在使用示例php文件返回用户名,我无法查看或更改其中的任何内容。

3 个解决方案

#1


1  

You don't have to use Ajax if you want to go to another page after POST request

如果要在POST请求后转到另一个页面,则不必使用Ajax

  1. Post the form.
  2. 发表表格。

  3. Validate data on server.
  4. 验证服务器上的数据。

  5. If credentials is valid put the username in cookie session which means the user has successfully logged in.
  6. 如果凭据有效,则将用户名放在cookie会话中,这意味着用户已成功登录。

  7. redirect the page to the main page.
  8. 将页面重定向到主页面。

I strongly recommend you to read more about PHP authentication and use third party libraries if possible.

我强烈建议您阅读有关PHP身份验证的更多信息,并尽可能使用第三方库。

NOTE: Using an unhashed value as a credential stored in cookie is completely unsafe.

注意:使用未散列值作为存储在cookie中的凭据是完全不安全的。

#2


0  

Apparently you have two pages, one is login form and second is the quiz page. You can save the username to a session(not cookie) from the login page itself and redirect to quiz page upon successful authentication. In quiz page you can easily retain the username from session variable.

显然你有两个页面,一个是登录表单,第二个是测验页面。您可以从登录页面本身将用户名保存到会话(而不是cookie),并在成功验证后重定向到测验页面。在测验页面中,您可以轻松保留会话变量的用户名。

The session will long last until a certain period of time that you've mentioned in settings.

会话将持续到您在设置中提到的特定时间段。

You can get this session variable throughout your application.

您可以在整个应用程序中获取此会话变量。

Using session is pretty straight forward in php, you can read it here on PHP.net

使用session在php中非常简单,你可以在PHP.net上阅读它

Use password_hash and password_verify (PHP 5 >= 5.5.0, PHP 7 ) with bcrypt for security when saving the passowrds.

保存passowrds时,使用密码_hash和password_verify(PHP 5> = 5.5.0,PHP 7)和bcrypt来确保安全性。

#3


-1  

please add your code.

请添加您的代码。

you can useheader() function in php to redirect your page to quiz page after getting valid data from user.

你可以使用php中的head()函数在从用户那里获得有效数据后将你的页面重定向到测验页面。

#1


1  

You don't have to use Ajax if you want to go to another page after POST request

如果要在POST请求后转到另一个页面,则不必使用Ajax

  1. Post the form.
  2. 发表表格。

  3. Validate data on server.
  4. 验证服务器上的数据。

  5. If credentials is valid put the username in cookie session which means the user has successfully logged in.
  6. 如果凭据有效,则将用户名放在cookie会话中,这意味着用户已成功登录。

  7. redirect the page to the main page.
  8. 将页面重定向到主页面。

I strongly recommend you to read more about PHP authentication and use third party libraries if possible.

我强烈建议您阅读有关PHP身份验证的更多信息,并尽可能使用第三方库。

NOTE: Using an unhashed value as a credential stored in cookie is completely unsafe.

注意:使用未散列值作为存储在cookie中的凭据是完全不安全的。

#2


0  

Apparently you have two pages, one is login form and second is the quiz page. You can save the username to a session(not cookie) from the login page itself and redirect to quiz page upon successful authentication. In quiz page you can easily retain the username from session variable.

显然你有两个页面,一个是登录表单,第二个是测验页面。您可以从登录页面本身将用户名保存到会话(而不是cookie),并在成功验证后重定向到测验页面。在测验页面中,您可以轻松保留会话变量的用户名。

The session will long last until a certain period of time that you've mentioned in settings.

会话将持续到您在设置中提到的特定时间段。

You can get this session variable throughout your application.

您可以在整个应用程序中获取此会话变量。

Using session is pretty straight forward in php, you can read it here on PHP.net

使用session在php中非常简单,你可以在PHP.net上阅读它

Use password_hash and password_verify (PHP 5 >= 5.5.0, PHP 7 ) with bcrypt for security when saving the passowrds.

保存passowrds时,使用密码_hash和password_verify(PHP 5> = 5.5.0,PHP 7)和bcrypt来确保安全性。

#3


-1  

please add your code.

请添加您的代码。

you can useheader() function in php to redirect your page to quiz page after getting valid data from user.

你可以使用php中的head()函数在从用户那里获得有效数据后将你的页面重定向到测验页面。