2016-08-31 4 views
0

내 세션이 내 로컬 호스트에서 올바르게 작동합니다. 하지만 라이브 서버에서 사용할 때는 로그인을 위해 먼저 로그 아웃해야합니다. 예를 들어 로그인해야 할 때 먼저 로그 아웃 한 다음 로그인해야합니다. 그렇지 않으면 빈 페이지가 표시됩니다. 왜 이런 일이 일어나는지 모르겠습니다. 내가 로그 아웃을 위해PHP : 라이브 서버에서 세션이 올바르게 작동하지 않습니까?

<?php 
session_start(); 
if(!isset($_SESSION['login'])) { 
header("location:Login.php"); 
} 
else { 
    $user_id = $_SESSION['user_id']; 
    $user_email = $_SESSION['user_email']; 
    include("db.php"); 

    ?> 
    <!DOCTYPE html> 
    <html lang="en"> 
    <head> 
     <meta charset="UTF-8"> 
     <title>User's Own Profile</title> 
     <link rel="stylesheet" href="css/bootstrap.min.css"> 
     <link rel="stylesheet" href="font-awesome-4.5.0/css/font-awesome.css"> 
     <link rel="stylesheet" href="css/custom.css"> 
     <link rel="stylesheet" href="main.css"> 
     <script src="js/jquery.min.js"></script> 
     <script src="js/bootstrap.min.js"></script> 
     <script src="js/newCustom.js"></script> 


    </head> 
    <body> 

    <div class="container"> 
     <?php 
      include 'customNav.php' 
     ?> 

    <!--Navbar--> 


    <div class="row topsecond"> 
     <div class="col-lg-12"> 
      <h3 class="heading">Ads</h3> 
     </div> 
    </div> 

     <!--Ads--> 


<!--  <div class="row"> 
      <div class="col-lg-8"> 
       <div class="col-lg-3 col-sm-5"> 
        <button type="button" class="btn btn-lg btn-primary">My Profile</button> 
       </div> 
       <div class="col-lg-3 col-sm-5"> 
        <a type="button" href="Search.php" class="btn btn-lg btn-primary">Find People</a> 
       </div> 
       <div class="col-lg-3 col-sm-5"> 
        <button type="button" class="btn btn-lg btn-primary">Message List</button> 
       </div> 
      </div> 

      <div class="col-lg-4"> 
       <div class="col-lg-6 col-sm-5"> 
        <a href="#"> 
         <button type="button" class="btn btn-lg btn-primary">New Likes</button> 
        </a></div> 
       </a> 

       <div class="col-lg-6 col-sm-5"> 
        <form> 
        <button type="button" class="g btn btn-lg btn-primary" ><span id="message"> <span class="glyphicon glyphicon-inbox"></span> </span> 
        </button> 
         <form> 

       </div> 


      </div> 


     </div> 

     --> 




     <!--Links--> 


     <div class="col-lg-8 left"> 

      <div class="row"> 
       <div class="row "> 
        <?php 
        $photo = mysqli_query($conn, "SELECT * FROM user WHERE user_id='$user_id'"); 

        while ($recordPhoto = mysqli_fetch_array($photo)) { 

        if ($recordPhoto == FALSE) { 
         die(mysqli_error("error message for the user")); 

        } 
        ?> 
        <div class="col-lg-4 col-sm-4 col-xs-4 img"> 

         <img class="center-block img-rounded" src="<?php echo "../shadi/images/" . $recordPhoto['user_photo1'] ?>" 
          alt="" 
          width="80%" height="220px"> 
        </div> 

        <div class="col-lg-4 col-sm-4 col-xs-4 img"> 

         <img class="center-block img-rounded" src="../shadi/images/team-hire.jpg" alt="" width="80%" height="220px"> 
        </div> 

        <div class="col-lg-4 col-sm-4 col-xs-4 img"> 
         <img class="center-block img-rounded" src="../shadi/images/team-hire.jpg" alt="" width="80%" height="220px"> 
         <?php 
         } 
         ?> 
        </div> 
       </div> 


       <div class="row upload"> 
        <!--<div class="col-lg-12 col-sm-5 col-xs-12"> 
        <div class="col-lg-12 col-sm-5 col-xs-12"> 
         <div class="form"> 
          <h4 for="exampleInputFile">File input</h4> 
          <input type="file" id="exampleInputFile"> 
         </div> 
        </div> 
        </div>--> 
        <div class="col-lg-4 col-sm-5 col-xs-12"> 
         <a href="userOwnProfileSetting.php"> 
          <div class="btn btn-lg btn-info edit"> 
           Edit Profile 
          </div> 
        </div> 
        </a> 

       </div> 
      </div> 
      <?php 
      $res = mysqli_query($conn, "SELECT * FROM user WHERE user_id=$user_id"); 

      while ($record = mysqli_fetch_array($res)) { 

      if ($record == FALSE) { 
       die(mysqli_error("error message for the user")); 

      } 
      ?> 
      <div class="col-lg-12 col-sm-12"> 
       <div class="row"> 
        <h3 class="heading col-sm-4"><u>Profile Settings</u></h3> 

        <div class="col-sm-8"> 
         <h3><u><?php echo $record['user_name']; ?></u></h3> 
        </div> 
       </div> 
       <div class=""> 
        <div class="row"> 
         <h4 class="col-sm-4">Gender :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_gender']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Date of Birth :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_dob']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Age :</h4> 

         <div class="col-sm-6 col-sm-6 col-xs-12"> 
          <h5>31 years</h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Height :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_height']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Weight :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_weight']; ?></h5> 
         </div> 
        </div> 
       </div> 
       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Race :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_race']; ?></h5> 
         </div> 
        </div> 
       </div> 
       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Religion :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_religion']; ?></h5> 
         </div> 
        </div> 
       </div> 
       <br> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Country :</h4> 

         <div class="col-sm-6"> 
          <h5> <?php echo $record['user_country']; ?> </h5> 
         </div> 
        </div> 
       </div> 


       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">State Origin :</h4> 

         <div class="col-sm-6"> 
          <h5> <?php echo $record['user_stateOfOrigin']; ?> 
          </h5></div> 
        </div> 
       </div> 


       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">State Living :</h4> 

         <div class="col-sm-6"> 
          <h5> <?php echo $record['user_stateLiving']; ?></h5> 
         </div> 
        </div> 
       </div> 


       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Marital Stauts :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_maritalStatus']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Career :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_career']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class=" col-sm-4">Educational Level :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_educationLevel']; ?></h5> 
         </div> 
        </div> 
       </div> 
       <br> 

       <div class=""> 
        <div class="row"> 
         <h4 class="col-sm-4">Relations for</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_relationshipfor']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class="col-sm-4">Plygamy :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_polygamy']; ?></h5> 
         </div> 
        </div> 
       </div> 
       <div class=""> 
        <div class="row"> 
         <h4 class="col-sm-4">Interest :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_interest']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class=""> 
        <div class="row"> 
         <h4 class="col-sm-4">Smoking :</h4> 

         <div class="col-sm-6"> 
          <h5><?php echo $record['user_smokingVape']; ?></h5> 
         </div> 
        </div> 
       </div> 

       <div class="row"> 
        <h4 class=" col-sm-4">Self Summary : <br> 
        </h4> 

        <div class="col-sm-6"> 
         <h5><?php echo $record['user_selfSummary']; ?></h5> 
        </div> 
       </div> 
       <br> 


       <div class="row"> 
        <div class="col-sm-4"> 

        </div> 
        <!--<div class="col-sm-8"> 
         <button type="button" class="btn btn-lg btn-warning">Submit</button> 
        </div>--> 
       </div> 
      </div> 

     </div> 

     <!--form done--> 


     <div class="col-lg-4"> 
      <div class="row right"> 
       <h2>Ads</h2> 
      </div> 
      <div class="row yes"> 
       <h2 class="status"><u>Status</u></h2> 
       <h4 class="gly"><span class="glyphicon glyphicon-heart"></span><?php echo $record['user_Likes'] . " Likes"; ?></h4> 


       <h4 class="gly"><span class="glyphicon glyphicon-user"></span> Normal Member</h4> 
       <h4 class="gly"><span class="glyphicon glyphicon-minus-sign"></span> Offline</h4> 
      </div> 

      <div class="row yes"> 
       <h3 class="status"><u>I'm looking for</u></h3> 

       <p class="nigga"> <?php echo $record['user_lookingFor']; ?> :D</p> 
      </div> 

      <div class="row yes"> 
       <h3 class="status"><u>Facebook Like Box</u></h3> 
      </div> 
     </div> 


     <?php 
     } 
     ?> 





    </div> 

    </body> 
    </html> 
    <?php 
} 
?> 

코드를 로그인 할 때
이이 내가 리디렉션됩니다 페이지 내 로그인 페이지

<?php 
session_start(); 
if(isset($_SESSION['user_id']) && $_SESSION['login']=="true") { 
    header("location:userOwnProfile.php"); 
    exit(); 
} 
else 
{ 

?> 


<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
     <head> 
      <meta charset="UTF-8"> 
      <title>Register</title> 
      <link rel="stylesheet" href="css/bootstrap.min.css"> 
      <link rel="stylesheet" href="main.css"> 
      <link rel="stylesheet" href="register.css"> 
      <script src="jquery-1.12.2.min.js"></script> 
      <script src="js/bootstrap.min.js"></script> 
     </head> 
<body> 

<div class="container"> 
    <nav class="navbar nav-top navbar-inverse"> 
     <div class="container-fluid"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
      </div> 
      <div class="collapse navbar-collapse" id="myNavbar"> 
       <ul class="nav navbar-nav"> 
        <li class="link one"><a href="index.php">Home</a></li> 
        <li class="link"> 
         <a class="dropdown-toggle" data-toggle="dropdown" href="#">Blog</a> 
        </li> 
        <li class="link"><a href="#">FAQ</a></li> 
        <li class="link"><a href="#">Terms & Cond</a></li> 
        <li class="link"><a href="#">Contact</a></li> 
       </ul> 
       <ul class="nav navbar-nav navbar-right"> 
        <li class="one"><a href="#">Facebook Login</a></li> 
        <li class="one"><a href="#">Login</a></li> 
       </ul> 
      </div> 
     </div> 
    </nav> 


    <div class="col-lg-4 col-lg-offset-4 col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 si"> 

     <h3 class="center"><u>MEMBERS LOG IN</u></h3> 
<BR> 

     <form action="Login.php" method="post"> 


      <div class="row"> 
       <div class="form-group"> 
        <label class="control-label col-sm-3" for="email">Email:</label> 
        <div class="col-sm-9"> 
         <input type="email" name="user_email" class="form-control" id="email" placeholder="Enter email" required> 
        </div> 
       </div> 

      </div> 
      <div class="row"> 
       <div class="form-group"> 
        <label class="control-label col-sm-3" for="pwd">Password:</label> 
        <div class="col-sm-9"> 
         <input type="password" name="user_password" class="form-control" id="pwd" placeholder="Enter password"> 
        </div> 
       </div> 
      </div> 

      <div class="row"> 
       <div class="col-lg-3 col-sm-3 col-md-3 "> 

       </div> 
       <div class="col-lg-9 col-sm-9 col-md-9 "> 
        <a href="#"><h4>Forgot Password</h4></a> 
       </div> 
      </div> 

      <div class="row"> 
       <div class="col-lg-3 col-sm-3 col-md-3 "> 

       </div> 
       <div class="col-lg-9 col-sm-9 col-md-9 "> 
        <label><input type="checkbox"> Remember me</label> 
       </div> 
      </div> 

      <div class="row"> 
       <div class="col-lg-3 col-sm-3 col-md-3 "> 

       </div> 
       <div class="col-lg-9 col-sm-9 col-md-9 "> 
        <!--<input class="btn btn-lg btn-danger">--> 
        <input type="submit" class="btn btn-lg btn-danger" name="submit" value="Login"> 
       </div> 
      </div> 





     </form> 
    </div> 
    <?php 
    include("db.php"); 
    /*if(isset($_POST['Go'])) { SIGNUP 
     $user_name = $_POST['user_name']; 
     $user_password = $_POST['user_password']; 
     $user_email = $_POST['user_email']; 
     echo $user_name . "<br>"; 
     echo $user_email . "<br>"; 
     echo $user_password . "<br>"; 
     $sql = "INSERT INTO user(user_name,user_email,user_password) VALUE ('$user_name','$user_email','$user_password')"; 
     if(mysqli_query($conn,$sql)) 
     { 
      echo "stored"; 
      header("location:http://localhost/window.php"); 
     } 
     else 
     { 
      die(mysqli_error($sql)); 
     } 
    }*/ 


    if(isset($_POST['submit'])) 
    { 
     $user_email = $_POST['user_email'];//real_escape_string 
     //echo $user_email; 

     $user_password = $_POST['user_password']; 
     $login_query="SELECT * FROM user WHERE user_email='$user_email' AND user_password='$user_password'"; 
     $run=mysqli_query($conn,$login_query) or die($conn); 
     if(mysqli_num_rows($run)>0) 

     { 
      $res = mysqli_query($conn, "SELECT * FROM user WHERE user_email='$user_email'"); 

      while ($record = mysqli_fetch_array($res)) { 

       $_SESSION['Name'] = $record['user_name']; 
       //$_SESSION['user_lname'] = $record['user_lname']; 
       //$_SESSION['user_status'] = $record['user_status']; 
       $_SESSION['user_email'] = $record['user_email']; 
       $_SESSION['user_id'] = $record['user_id']; 
       $_SESSION['login'] = "true"; 

      } 



      //echo $_SESSION['user_fname'] . $_SESSION['user_lname']; 
      //echo "NAME: " . $_SESSION['Name']; 

      echo '<script>window.location="userOwnProfile.php"</script>'; 

        } 
     else 
      echo "<p style='color: red; margin-top: -28px;'>User name or password incorrect</p>"; 
    } 




    ?> 


    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> 
     <div class="jumbotron bottom"> 

      <div class="row bott"> 
       <div class="col-lg-3 col-sm-3 col-xs-3 low"> 
        <h3>Blog Feeds</h3> 

       </div> 

       <div class="col-lg-3 col-sm-3 col-xs-3 low"> 
        <h3>Testimony</h3> 

        <h5> 

        </h5> 

       </div> 

       <div class="col-lg-3 col-sm-3 col-xs-3 low"> 
        <h3>Facebook Like Box</h3> 
       </div> 
      </div> 

     </div> 
</div> 






</body> 
</html></title> 
</head> 
<body> 

</body> 
</html> 
<?php } ?> 

입니다

<?php 
session_start(); 
unset($_SESSION['Name']); 
unset($_SESSION['user_email']); 
unset($_SESSION['user_id']); 
unset($_SESSION['login']); 
header("location:index.php"); 

session_destroy(); 
exit(); 
?> 

내가 원하는 이것이 생방송에서 왜 일어나고 있는지 알기 위해 ver. 왜 나 자신이 로그인하려면 먼저 로그 아웃해야합니까?

+0

로그 아웃 스크립트를 게시하십시오 –

+0

나는 또한 넣어 동일한 문제가 있었다 ("db.php"); before session_start(); –

+0

@NeelIon : 로그 아웃 코드를 게시했습니다. –

답변

1

userOwnProfile.php 스크립트는 헤더를 보내기 전에 출력을 보냅니다. <?php 태그 앞에 약간의 공백이 있습니다. 그 공백을 제거하십시오. 희망이 도움이 될 것입니다

+0

에디터 (phpStorm)에서도 인코딩 설정이 필요합니까? –

+1

BOM이있는 경우 BOM없이 UTF-8로 만듭니다. –

+0

대단히 고마워 .. 그게 .. !!! –

관련 문제