简体   繁体   English

创建推荐链接以在注册表单上自动填写用户名

[英]Creating a referral link to auto fill a user username on the registration form

How to create a referral link to auto fill a user username on the registration form?如何创建推荐链接以在注册表单上自动填写用户名? I don't have any idea on how does this work and even how to start it.我不知道这是如何工作的,甚至不知道如何启动它。 All I have is:我只有:

https://mywebsite.com/register?ref=<?php echo ($user['username']);?>

Please, I need helps.拜托,我需要帮助。 Thanks in advance.提前致谢。

You can use PHP's superglobal $_GET to grab the query string from the URL, then add that to the input's value.您可以使用 PHP 的超全局$_GET从 URL 中获取查询字符串,然后将其添加到输入值中。

$referral = htmlspecialchars($_GET['ref'] ?? '');

This will set the $referral variable to the given referral if it's there, otherwise, it'll be an empty string.这会将$referral变量设置为给定的引用(如果存在),否则它将是一个空字符串。 Now you can use that in your input so set the referral.现在您可以在输入中使用它,以便设置推荐。

<input type="text" name="referral" value="<?php echo $referral; ?>" />

Then when posted, you can check if a referral was set for this new registration and handle that accordingly.然后在发布时,您可以检查是否为此新注册设置了推荐并相应地处理。 Whether that'll be setting a value in the database, sending the referral user an email, etc.是否会在数据库中设置一个值,向推荐用户发送 email 等。

if (isset($_POST['referral'])) {
    // Handle the referral.
}

Hope that give's you some ideas.希望能给你一些想法。

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

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