简体   繁体   English

如果确认电子邮件,则将用户重定向到登录页面

[英]Redirect User to Login Page if Email is Confirmed

So on my website I send out emails with links that the user must follow to verify his/her email. 因此,在我的网站上,我发送了带有链接的电子邮件,用户必须遵循这些链接来验证其电子邮件。 If the user clicks the link in the email, I want the user to be taken to a page that thanks him/her for confirming his/her account, and then redirect the user to the login page. 如果用户单击电子邮件中的链接,我希望将用户带到感谢他/她确认其帐户的页面,然后将用户重定向到登录页面。 How can I do this? 我怎样才能做到这一点? I tried using the PHP header function but this doesn't work because I must send headers to display the "thank you" message, so I can't use that function. 我尝试使用PHP标头函数,但这不起作用,因为我必须发送标头以显示“谢谢”消息,所以我不能使用该函数。 What can I do to get this to work? 我该怎么做才能使它正常工作?

You can use a meta refresh to do the redirect after a set period of time. 您可以在一段时间后使用元刷新来进行重定向。 To redirect in 5 seconds, place this code in the <head> of your web page: 要在5秒内重定向,请将以下代码放在网页的<head>中:

<meta http-equiv="refresh" content="5;URL='http://example.com/'">

You can also do this with an HTTP header: 您也可以使用HTTP标头执行此操作:

header('Refresh: 5;URL='http://example.com/');

Or use JavaScript: 或使用JavaScript:

<script type="text/javascript">
function delayedRedirect(){
    window.location = "http://example.com/"
}
</script>
<body onLoad="setTimeout('delayedRedirect()', 3000)">

try php sleep() function enter link description here 尝试php sleep()函数在此处输入链接描述

you may use like this 你可以这样使用

<?php

if(email code validation evaluates to true by comparing to DB record)
{
echo"thank you message"
sleep(20);
header('location:http://www.somesite.com/login.php');
}
?> 

if its giving some header error. 如果它给一些头错误。 use ob_start() just after 在之后使用ob_start()

The simplest way is probably to use GET. 最简单的方法可能是使用GET。

The way this works is that you send a link with GET-variables, that you can extract with php and activate the email adress. 它的工作方式是发送带有GET变量的链接,您可以使用php提取并激活电子邮件地址。

Eg if the user receives the link: http://example.com/verifymail.php?email=johndoe@example.com&verify=true 例如,如果用户收到链接: http : //example.com/verifymail.php?email=johndoe@example.com&verify=true

then the script at example.com/verifymail.php can access the email and verify variables like so: 然后example.com/verifymail.php中的脚本可以访问电子邮件并验证变量,如下所示:

<?php
  if($_GET['verify'] == 'true'){
    verifyEmail($_GET['email']);
  }
?>

you can form the link in any language, just follow the convention: - ? 您可以按照任何语言形成链接,只需遵循以下约定:-? after the URL tells php that GET-variables follow. 在URL告诉php跟随GET变量之后。 Variables come in name=value pairs. 变量以名称=值对的形式出现。 and variables are separated by & 变量之间用&分隔

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

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