从数据库中为不同用户访问的页面选择信息 [英] Select information from the database for a page accessed by different users

查看:46
本文介绍了从数据库中为不同用户访问的页面选择信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景:

用户 A: 访问网站并选择问卷.问卷在同一域的不同页面上分开,例如:

User A: Access the website and choose a questionnaire. The questionnaires are separated on different pages in the same domain, for example:

主页:surveys.com"

Home: "surveys.com"

问卷:

  • surveys.com/type1"

  • "surveys.com/type1"

surveys.com/type2"

"surveys.com/type2"

选择一个后,他(用户A)输入以下信息:

After choosing one, he (User A) puts the following information:

1 = 收件人的电子邮件

2 =他的电子邮件

然后提交.

用户 B: 收到此问卷链接的人 (surveys.com/type1).

User B: Person who received this link to the questionnaire (surveys.com/type1).

我想做的是:用户B访问问卷页面的链接时,它已经被编程为向用户A发送回复strong> 谁在主页上留下了他的电子邮件.

What I want to do is: When User B accesses the link to the questionnaire page, it is already programmed to send responses to User A who left his email on the home page.

我的想法是将用户A提供的信息保存在变量中并保存在数据库中.当用户 B 访问页面时,我从数据库中获取相应的信息并在页面上使用它来执行我想要的操作.

My idea was to save the information provided by User A in variables and save it in the database. When User B accesses the page, I take the respective information from the database and use it on the page to do what I want.

问题是:如何将不同用户的信息分开?(也许很简单,但我不知道怎么做)

The problem is: How would I separate information for different users? (maybe it's simple, but I don't know how to do it)

这就是我到目前为止所做的:

That's what I've done so far:

主页:

<?php

include_once 'includes/dbh.php';
require  'email/PHPMailerAutoload.php';

$recipient = $_POST['emailFor'];
$sender = $_POST['senderEmail'];
$message = $_POST['message'];

$sql = "INSERT INTO users(email, body) VALUES('$sender', '$message');";
mysqli_query($conn, $sql;)

问卷页面 (survey.com/type1):

<?php

include_once 'includes/dbh.php';
$sql = "SELECT * FROM users;";
$result = mysqli_query($conn, $sql);

?>

我认为不可能使用会话,因为需要将信息传递给另一个用户.我也考虑过创建一个 uniq 链接的可能性,但我不知道该怎么做.无论如何,如果您能帮忙提供代码示例,我将不胜感激.

I think it is not possible to use sessions, since the information will need to be passed on to another user. I also thought about the possibility of creating a uniq link maybe, but I have no idea how to do it. Anyway, I'll be grateful if you can help with code examples for this.

推荐答案

我可以尝试为您提供以下解决方案:当用户 A 将电子邮件发送给用户 B 时,您将其保存在表中,例如surveys_send,并带有随机生成的唯一代码.当用户 B 访问来自用户 A 的链接时,它看起来像survey.php?randomcode=12345 并且随机码是发送电子邮件时生成的唯一代码.当用户输入此调查脚本时,它会检查并向用户 A 发送有人访问了此 URL 的响应.

I can try to provide you solution below: When user A send the email to user B you save it in table like surveys_send with an unique code that will be randomly generate. When user B visits the link from user A it can look something like survey.php?randomcode=12345 and randomcode is this unique generated code when sending the email. When the user enters this survey script it will check and send an response to user A that someone visited this url.

这篇关于从数据库中为不同用户访问的页面选择信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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