douyou7797 2017-06-23 18:20
浏览 109
已采纳

密码有效时,根据用户名将用户重定向到页面

I am trying to create a simple login system, without MySQL, just so that my clients can log in, and get directed to a page that will have information showing any links to files, and any meetings.

I have got this:

    //If the user is validated and every thing is alright, then grant the user access to the secured account page 
                //otherwise, display error message to the user
            if ($vpb_error == '')
            {
                if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
                {
                    echo '<font style="font-size:0px;">completed</font>';
                }
                else
                {
                    echo '<div class="info">Sorry, it seems your information are incorrect and as a result, we are unable to create the required sessions to log you into your account. Please enter your valid account information to proceed. Thanks.</div>';
                }

            }
            else
            {
                echo $vpb_error;
            }
            fclose($vpb_databases);
        }
    }
    else
    {
        echo '<div class="info">Sorry, we could not get your valid username and password to process your login. Please try again or contact this website admin to report this error message if the problem persist. Thanks.</div>';
    }
}
//*********************************************************The login process ends here**********************************************************

How can I make it so that if everything is okay, it will then redirect them to a page based on their username, ie if their username was james, they would be sent to james.php.

Cheers Lewis

  • 写回答

3条回答 默认 最新

  • dongsimu4422 2017-06-23 18:25
    关注

    I'm guessing that the following if statement is the 'success' branch of code.

    https://stackoverflow.com/a/768472/296555

    <?php
    if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
    {
        header('Location: '.$_SESSION['validusername'] . '.php');
    }
    

    EDIT

    You should really look at cleaning up your code; it's quite messy and looks overly complicated. You're mixing HTML and PHP, although not a show stopper, is generally frowned upon. This is where simple/easy-to-use frameworks come in. Even if you don't use them you should spend some time reading them because they do a lot things right and you'll learn more in a week than a lifetime of fumbling through it. Keep going... it's always fun to come back to code that you've written years ago and think, 'Man, I used to suck!'.

    Ex.

    <?php
    // This looks like no error but then...
    if ($vpb_error == '')
    {
        if(isset($_SESSION['validfullname']) && isset($_SESSION['validusername']) && isset($_SESSION['validemail']) && isset($_SESSION['validpassword']))
        {
            // Mixing HTML directly in a script file
            echo '<font style="font-size:0px;">completed</font>';
        }
        // there is an error here.
        else
        {
            echo '<div class="info">Sorry, it seems your information are incorrect and as a result, we are unable to create the required sessions to log you into your account. Please enter your valid account information to proceed. Thanks.</div>';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突