$ _SESSION不起作用。有问题?

时间:2015-06-19 15:09:22

标签: php

我知道有一个类似的问题,但我相信我的文件的问题是不同的.code如下:

<?php
require_once 'resources/core.inc.php';
require_once 'resources/connect.inc.php';
/* 
* retreive all posts from Post_table and populate them below.
*/?>
<html>
 <head><title>View Posts.</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 , maximum-scale=1">
    <link href='http://fonts.googleapis.com/css?family=Indie+Flower|Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="resources/Viewposts.css"></head>
<body><?php
if(isset($SESSION['s_id'])||isset($_SESSION['f_id'])){
   $result = $conn->prepare("SELECT * FROM post_table ORDER_BY p_id DESC");
   $result->execute();
   $row = $result->fetchAll();
   foreach($row as $rows){

    echo $rows['p_id'].'<br>';
    echo $rows['u_id'].'<br>';
    echo $rows['u_name'].'<br>';
    echo $rows['p_title'].'<br>';
    echo $rows['p_body'].'<br><hr>';
    }
   }else{
echo '<center><h1 id="logmsg">Please Log in.</h1></center>';}
?></body>

问题是甚至会话已设置它正在呼应&#34;请登录&#34;。 如果我使用

<?php

  //faculty login page.
 //if logged in show upload option/show login option.

  require_once 'resources/core.inc.php';
  require_once 'resources/connect.inc.php';

   if(isset($_SESSION['f_id'])&&!empty($_SESSION['f_id'])){
    echo 'faculty';
    }elseif(isset($_SESSION['s_id'])&&!empty($_SESSION['s_id'])){
   echo 'student';
   }
      else{
  echo 'log in now.';
   }

  ?>

它说我已登录。

1 个答案:

答案 0 :(得分:1)

详细说明我的评论,请更改此行......

if(isset($SESSION['s_id'])||isset($_SESSION['f_id'])){

为...

if (isset($_SESSION['s_id']) || isset($_SESSION['f_id'])) {