简体   繁体   English

会话在邮件验证注册中不起作用

[英]session doesn't work in mail verification register

i use email verification for my registration. 我使用电子邮件验证进行注册。 after register i login user and keep it's id in session (i have a session class for storing user login info) and then send a link to his mail and after all i redirect user to another page and tell him please check ur mail and click.... 注册后,我登录用户并在会话中保留其ID(我有一个用于存储用户登录信息的会话类),然后发送链接到他的邮件,毕竟我将用户重定向到另一个页面,并告诉他请检查您的邮件并单击。 ...

this is link that i send to user mail(for now i just send to my mail by default) 这是我发送给用户邮件的链接(目前,我默认情况下只是发送给我的邮件)

$body.="<h4><a href='http://www.habibabdollahi.com/fani/home/activate.php?user=".$user->id.
                "&code=".$user->mail_verify_code."'>فعال سازی</a></h4>";    

in activate.php i verify user with his id and his code but it seem i dont access the session after click link in the mail. 在activate.php中,我用用户名和代码验证用户,但单击邮件中的链接后,似乎无法访问会话。 but if if redirect user after register to the activate.php like the last link there is no problem and i have session in this situation. 但是,如果如果将用户重定向到像最后一个链接一样的Activate.php注册后,则没有问题,在这种情况下,我有会话。

redirect_to("home/activate.php"."?user=$user->id&code=$user->mail_verify_code");

whats the problem friends, i'm going to be mad! 有什么问题的朋友,我要疯了!

just focus on session, i just want know why my session lost after redirect via mail and this my session class 只专注于会话,我只想知道为什么通过邮件重定向后我的会话丢失了,这是我的会话类

class Session{

    public $user_id;
    private $loged_in=false;
    private $verified_mail=false;
    private $verified_mobile=false;
    private $user_type; 


    function __construct(){
        session_start();
        $this->check_login();
        $this->check_verification();// ham mobile va ham mail ra check mikonad
        $this->check_user_type();
    }

    /* It'es get method, that get the loged status  */
    public function is_logged_in(){
        return $this->loged_in;     
    }

    public function login($user){
        //database should find user based on username and password
        if($user){
            $this->user_id=$_SESSION['user_id']=$user->id;
            $this->loged_in=true;
        }
    }

    public function verify_mobile($is_verified){
        if($is_verified){
            $this->verified=$_SESSION['verified_mobile']=$is_verified;
        }else{
            return false;   
        }
    }

    public function verify_mail($is_verified){
        if($is_verified){
            $this->verified=$_SESSION['verified_mail']=$is_verified;
        }else{
            return false;   
        }
    }
    /******  user type ra be khater miseparad    *********************/
    public function remember_user_type($user){
            if($user){
                $this->user_type=$_SESSION['user_type']=$user->user_type_id;
            }
    }
    public function get_user_type(){

        return $this->user_type;    
    }


    private function check_user_type(){
        if(isset($_SESSION['user_type'])){
            $this->user_type=$_SESSION['user_type'];
        }

    }
    // che mobile va ya che mail verify shode bashad okeye
    public function get_is_verified(){
        return ($this->verified_mobile || $this->verified_mail);
    }

    public function get_is_verified_mobile(){
        return $this->verified_mobile;      
    }

    public function get_is_verified_mail(){
        return $this->verified_mail;        
    }

    public function logout(){
        unset($_SESSION['user_id']);
        unset($this->user_id);
        $this->loged_in=false;
    }

    public function get_user_id(){
        return $this->user_id;  
    }

    private function check_login(){

        if(isset($_SESSION['user_id'])){
            $this->user_id=$_SESSION['user_id'];
            $this->loged_in=true;

        }else{
            unset($this->user_id);
            $this->loged_in=false;
        }

    }//check_login

    private function check_verification(){

        if(isset($_SESSION['verified_mail'])){
            $this->verified_mail=$_SESSION['verified_mail'];
            //$this->verified=true; 
        }

        if(isset($_SESSION['verified_mobile'])){
            $this->verified_mobile=$_SESSION['verified_mobile'];
            //$this->verified=true;
        }

    }


}//class end

$session=new Session();
//var_dump($session);

You may try this 你可以试试这个

if(isset($_SESSION['user_id'])){
        $this->user_id=$_SESSION['user_id'];
        $this->loged_in=true;

    }

instead of 代替

if(isset($_REQUEST['user'])){
        $this->user_id=$_REQUEST['user'];
        $this->loged_in=true;

    }

because of use pass user parameter on url 由于使用url传递user参数

$body.="<h4><a href='http://www.habibabdollahi.com/fani/home/activate.php?user=".$user->id.
                "&code=".$user->mail_verify_code."'>فعال سازی</a></h4>";  

After the verification code refresh the session and redirect the user to login page When user coming for login then check if user is Active then all user data is send to session Array I am not Expert but give a advice 在验证码刷新会话并将用户重定向到登录页面之后,当用户要登录时,请检查用户是否处于活动状态,然后将所有用户数据发送到会话Array我不是专家,但请提供建议

first take take user identity ID which you select for login 首先获取您选择登录的用户身份ID

then send those ID to login function and then give him session 然后将这些ID发送给登录功能,然后进行会话

Just try that 试试看

private function check_login($userID){
     Used Fetch Query there for login authentication and then give him to session ...       
your session code is here.........................  and redirect or return true   
}

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

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