doujinai2183 2013-02-15 12:24
浏览 24
已采纳

登录功能似乎无法正常运行

I've been sitting here pondering this for a good 30 minutes now and I just can't see what's wrong.

I've added prints but it just doesn't seem to be contacting the database correctly or not pulling the data from it correctly.

$conf['sql_host'] = 'localhost';
$conf['sql_user'] = 'root';
$conf['sql_pass'] = '';
$conf['sql_data'] = 'c_webauth';

    mysql_connect( $conf['sql_host'], $conf['sql_user'], $conf['sql_pass'] ) or die( 'Connection failed: '.mysql_error() );
    mysql_select_db( $conf['sql_data'] );



function login( $user, $pass ){

    session_regenerate_id();
        if ( isset( $_SESSION['user_id'] ) ) {
            unset( $_SESSION['user_id'] );
        }

        $qry = mysql_query( "SELECT user_id, user, user_group, user_name FROM c_users where user='$user' AND pass='".md5($pass)."'" );

        if ( mysql_num_rows( $qry ) > 0 ) {
            session_regenerate_id();

            while ( $data = mysql_fetch_array( $qry ) ) {
                $_SESSION['user_id'] = $data['user_id'];
                $_SESSION['user_group'] = $data['user_group'];
                $_SESSION['user'] = $data['user'];
                $_SESSION['user_name'] = $data['user_name'];

                // Debug
                echo $_SESSION['user_id'];
                echo $_SESSION['user_group'];
                echo $_SESSION['user'];
                echo $_SESSION['user_name'];

                session_start( ); 
            }
        }
}

login( "username", "password" );

Anychance you can see whats wrong?

Everyone has mentioned that I had my session_start(); in the wrong place, but the echo's print nothing, absolutely no errors anywhere.

  • 写回答

5条回答 默认 最新

  • douzhou7656 2013-02-15 12:28
    关注

    You are calling session_start() at the end instead before doing session checks

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

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线