2013-03-10 83 views
1

我的代碼是這樣的。這是一個登錄頁面。我在提交表單後創建會話。但會話不在這裏創建。但我已經在頂部創建了一個會話來測試它的工作。我的PHP版本是5.3+。它之前運作良好。但託管公司有更新並且問題開始。所有其他的事情都可以。php會話在php中提交表單後無法運行5.3

<?php 
    ob_start(); 
    session_start(); 
    $_SESSION['sessid'] = 123456789; 
    print_r($_SESSION); 
    include('db_connect.php'); 
    ?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <link rel="stylesheet" href="css.css" type="text/css" /> 
    <title>test</title> 
    </head> 
    <body class="oneColElsCtrHdr"> 
    <div id="container"> 
     <div id="header"> <a href="index.php?category=all"><img src="main_logo1.png" border="0" alt="logo" height="100" /></a> 
     <h2>Celebrating Life Admin Panel</h2> 

     <div class="clr"></div> 
     </div> 
     <div class="clr"></div> 
     <div id="mainContent"> 
    <?php 
    if(isset($_POST['submit2'])) 
    { 
     $username = mysql_real_escape_string($_POST['username']); 
     $password = md5($_POST['password']); 
     $query = "SELECT COUNT(*) as num FROM user WHERE username = '$username' AND password = '$password'"; 
     $result = mysql_fetch_assoc(mysql_query($query)); 
     //$result); die(); 
     if($result['num'] > 0) 
     { 
      $_SESSION['logged_in'] = TRUE; 
     } 
     else 
      $_SESSION['error'] = "Wrong username or password."; 
     mysql_close($conn); 
    } 
    echo '<h3>Admin Login</h3>'; 
    if($_SESSION['error']!=""){ 
     echo '<div class="error">'.$_SESSION['error'].'</div>'; 
     unset($_SESSION['error']); 
    } 
    ?> 

    <?php if(!$_SESSION['logged_in']){ $_SESSION['sessidd'] = 123456789564656;?> 
     <form action="login.php" method="post"> 
      <table width="300" border="0" cellspacing="0" cellpadding="6" style="margin:0 auto 20px"> 
      <tr> 
       <th colspan="2" scope="col">&nbsp;</th> 
      </tr> 
      <tr> 
       <td>Username</td> 
       <td><input type="text" name="username" /></td> 
      </tr> 
      <tr> 
       <td>Password</td> 
       <td><input type="password" name="password" /></td> 
      </tr> 
      <tr> 
       <td colspan="2" align="center"><input type="submit" name="submit2" value="Login" /></td> 
      </tr> 
      </table> 
     </form> 
    <?php }else{ ?> 
     <table width="300" border="0" cellspacing="0" cellpadding="6" style="margin:0 auto 20px"> 
      <tr> 
       <th colspan="2" scope="col"> 
       You have successfully logged in.<br /> 
       <a href="index.php?category=all">SHOW ALL REGISTRATION DATA</a> 
       </th> 
      </tr> 
      </table> 
    <?php } ?> 

     </div> 
     <div id="footer"> 

     </div> 
    </div> 
    </body> 
    </html> 
    <?php ob_flush(); ?> 
+0

也許最壞的登錄腳本我'have see:D but not not a error here:'if if($ result ['num']> 0) { $ _SESSION ['logged_in'] = TRUE; } 其他{....}' – 2013-03-10 19:39:51

回答

1

你有一些用戶數據類似

   if($result['num'] > 0) 
     { 
     session_register("id"); 
     $id = $result['id']; 
     $_SESSION['logged_in'] = $id; 
       } 

,而不是

  if($result['num'] > 0) 
     { 
     $_SESSION['logged_in'] = TRUE; 
     } 

註冊您的會話希望這將有用你