dongwuwei0718 2014-10-13 16:00
浏览 45
已采纳

电子邮件中的验证链接

Been trying this for ages :(

Upon registering, each user gets a randomly generated number which is stored in a table called "hash".

After much turmoil I have set up phpmailer and got the whole email process working, all fine, no worries.

BUT I have encountered a problem and I have even read answers on this site that haven't helped. I simply want to create a unique activation link depending on the hash. So for example:

User with "hash" as "12345" gets their verification email, I want the hyperlink to look like this - www.example.com/verify.php?hash=12345

And the same for each other user, here's how I'm currently trying it

<?php
$link_address = "verify.php?hash='.$hash.'";
echo "<a href='$link_address'> Activate </a>";   
?>

This displays "Activate "; ?>"

Very weird :(

EDIT

This is the guide I've previously tried to copy from - http://code.tutsplus.com/tutorials/how-to-implement-email-verification-for-new-members--net-3824

It is outdated and the default mail() function doesn't work for what I want, I'm particularly up to Step 5

EDIT 2

Mail body generation code

$body             = file_get_contents('C:\wamp\www\Game\examples\contents.html');

BIG EDIT!!

New code:

<?php


include("connect.php");

$username = $_POST['username'];


$id_get = mysqli_query($con,"SELECT units.id, users.id, users.username FROM units, users WHERE     users.username = '$username' AND units.id = users.id");
$gotid = mysqli_fetch_array($id_get);
$id4 = $gotid["id"];

$stuff_get = mysqli_query($con,"SELECT users.id, users.email, users.hash, users.username FROM users     WHERE users.username = '$username' AND users.id=$id4");
$gotstuff = mysqli_fetch_array($stuff_get);
$hash2 = $gotstuff['hash'];
$email2 = $gotstuff['email'];
$username2 = $gotstuff['username'];
echo "Your username is ",$username2,"<br>";
echo "Your activation code is ",$hash2,"<br>";

?>

From there I'm trying to get the submitted username (from the registration) and get information from the database (IDs, emails etc) then simply display the username and the hash in the email.

Usually this would be super easy but I'm getting the good old "Notice: Undefined index: username"!!

EDIT

For a completely simple run down on the situation.

I want to be able to get one variable from a page to another page for example.

page1.php

Has a variable called "$users"

page2.php

Wants to echo $users

But I do not know how to make the variable $users specifically from page1.php available on page2.php!

  • 写回答

2条回答 默认 最新

  • dongmei9020 2014-10-13 17:37
    关注
    "verify.php?hash='.$hash.'"; 
    

    Isn't Correct, you don't need the apostrophy and the dot to include the variable in a double quoted string. try

    "verify.php?hash=$hash";
    

    then do something like this mail($email, 'Please activate your account', "Hello " . $username. ", Thank you for registering with us. Please visit the link below so we can activate your account: http://www.example.com/verify.php?hash=" . $hash . " -- Example team");

    Then on you verify page use

    S_GET['hash'] 
    

    and check if it's correct against a database. I would also add the email in the url so you can check the email and code against each other, just in case you give out the same hash twice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输