douxin8749 2014-12-31 10:37
浏览 26
已采纳

PHP登录会话和回显用户名

The problem is on my login page everything works just fine but the problem here is when i successfully login the username doest show up at the main page.

include ('connect.php');

if (($_SERVER['REQUEST_METHOD'] == 'POST') && (!empty($_POST['action']))):
    $usernameLog = $_POST['usernameLog'];
    $passwordLog = $_POST['passwordLog'];
    $valid = true;

     if($valid == TRUE){
    include('connect.php');

    $usernameLog = mysql_real_escape_string($usernameLog);
    $passwordLog = mysql_real_escape_string(md5($passwordLog));

    $sql = mysql_query("SELECT * FROM register WHERE username = '$usernameLog' AND passconf = '$passwordLog'");


    if(mysql_num_rows($sql) > 0){

        //if true then lets go to the logged in page
        session_start();

        $_SESSION['logat'] = "da";

        header('location: BlogWorld.php');

I am not sure what's going wrong. Please help

//codes sesssion for the main page ie when user is successfully logged in

include('connect.php');

// Start session
    session_start();


// Check if user is logged and existing session
    if(isset($_SESSION['username'])) {
            include ("connect.php");

// Content for user logged
    echo "Welcome ".$username." :) - <a href='logout_Blog.php'>Logout</a>";
    } else {
// Redirecting to login page
    Header("Location: ./");
  • 写回答

2条回答 默认 最新

  • douyao2529 2014-12-31 10:40
    关注

    Add session_start() at the top of the pages where you are using session.

    And store

    $_SESSION['username'] = $usernameLog;
    

    Then echo $_SESSION['username'];

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

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器