duan89197 2014-05-18 16:17
浏览 34
已采纳

登录使用激活后的PHP身份验证或会话

I'm new to PHP, is there any way to direct logged the user in after the activation was success using PHP authentication (auth) or session?

Here is my activation script:

<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
$username = $_POST['username'];
$activation_code = $_POST['activation_code'];
$db_host = "localhost";
$db_name = "databasename";
$db_use = "root";
$db_pass = "password";
$link = mysqli_connect($db_host, $db_use, $db_pass);
mysqli_select_db($db_name, $link);
$command = "UPDATE email_activation SET check_activation='$activation_code' WHERE username='$username' and activation='$activation_code'";
$result = mysqli_query($command);
if ($result) {
echo "Congratulations. Your membership has been activated …";
}else{
echo ("You've entered an invalid username / activation code – please retry");
}
}
?>
  • 写回答

2条回答 默认 最新

  • douqianzha6213 2014-05-18 16:19
    关注

    yes you can.. just put this code after this

    if ($result) {
    echo "Congratulations. Your membership has been activated …";
    $_SESSION['user_logged'] = '1';
    header("location:afterloginpage.php");
    }else{
    echo ("You've entered an invalid username / activation code – please retry");
    }
    }
    

    or if you want to save session, you can always check if session is set or not

    if (isset($_SESSION['user_logged'])) {
      //User directly logged in
    }else {
      //Navigate user to login page
      header("location:loginpage.php");
    }
    

    also dont forget to initialize session_start(); at the top of the php file

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

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?