【问题标题】:PHP session expired error on localhost XAMPP server but when i upload the project on remoter it's working without error本地 XAMPP 服务器上的 PHP 会话过期错误,但是当我在遥控器上上传项目时,它可以正常工作
【发布时间】:2015-10-11 19:23:09
【问题描述】:

您好,如果有人能帮我解决这个问题,我将不胜感激。我花了将近三天的时间试图解决这个问题,但我无法解决。

我的session.php 文件:

<?
class Session
{
   var $time;         //Time 
   var $url;          //The page url 

   /* Class constructor */
   function Session(){
     // $this->time = time();
      $this->startSession();
      //$_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 30     minutes from the starting time

   }

   function startSession(){
      //global $database;  //The database connection
      session_start();   //Tell PHP to start the session
      /* Set referrer page */
      if(isset($_SESSION['url'])){
         $this->referrer = $_SESSION['url'];
      }else{
         $this->referrer = "/";
      }
      /* Set current url */
      $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];

   }
};
//-----------------------------------------
// Start new wession
//-----------------------------------------
$session = new Session;
?>

本地主机输出见下文:

time = time(); $this->startSession(); //$_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 30 minutes from the starting time } function startSession(){ //global $database; //The database connection session_start(); //Tell PHP to start the session /* Set referrer page */ if(isset($_SESSION['url']) && $_SESSION['url'] != '/index.php'){ $this->referrer = $_SESSION['url']; }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF']; } }; //----------------------------------------- // Start new wession //----------------------------------------- $session = new Session; ?> 1) ? 's':''; return count($items); }*/ $uniqCustomerId = $_SESSION['uCustomerId']; //dmWListTotalLeft(); $query = mysql_query("SELECT * FROM `wishlist` where `uniqCustomerId` = $uniqCustomerId"); //$num_rows = mysql_num_rows($query); if(mysql_num_rows($query) !=0) { return mysql_num_rows($query); }else{ return 0; } } //----------------------------------------- // Total items //----------------------------------------- function dmWListTotal() { if(!isset ( $_SESSION['dm_cartmj01'])){ $dm_cart = 0; }else{ $dm_cart = $_SESSION['dm_cartmj01']; } if (!$dm_cart) { //echo "Your Wishlist is empty"; $dm_cart = 0; return ''; } else { //echo "Your Wishlist"; // Parse the cart session variable $items = explode(',',$dm_cart); $s = (count($items) > 1) ? 's':''; return '
You have '.count($items).' item'.$s.' in your wishlist
'; } } // Back to catalogue //----------------------------------------- // Show List NEW //----------------------------------------- function dmWListShowNew() { // init $uniqCustomerId = $_SESSION['uCustomerId']; //dmWListTotalLeft(); $sn = 1; $result = mysql_query("SELECT * FROM `wishlist` where `uniqCustomerId` = $uniqCustomerId"); $num_rows = mysql_num_rows($result); // START if items exists in wishlist if($num_rows == 0){ $output[] = "
Your wishlist is empty
"; }else{ $output[] = '
'; while ($row = mysql_fetch_assoc($result)) { $id = $row['itemId']; $output[] = '
'; // ul start1 $result2 = mysql_query("SELECT * FROM `products` where prod_id ='".$id."LIMIT 1'"); while ($row2 = mysql_fetch_assoc($result2)) { $output[] = '
'.$sn.'
'; $output[] = '

【问题讨论】:

    标签: php session xampp localhost


    【解决方案1】:
    <?
    
    ?>
    

    而不是使用下面的标签

    <?php
    
    ?>
    

    更新: 我已经用 Hello() 方法更新了类,它将返回 larvel hello

    <?php
    
    class Session
    {
       var $time;         //Time 
       var $url;          //The page url 
    
       /* Class constructor */
       function Session(){
         // $this->time = time();
          $this->startSession();
          //$_SESSION['expire'] = $_SESSION['start'] + (1 * 60) ; // ending a session in 30     minutes from the starting time
    
       }
    function Hello(){
    
    echo "laravel hello";
    
    }
       function startSession(){
          //global $database;  //The database connection
          session_start();   //Tell PHP to start the session
          /* Set referrer page */
          if(isset($_SESSION['url'])){
             $this->referrer = $_SESSION['url'];
          }else{
             $this->referrer = "/";
          }
          /* Set current url */
          $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
    
       }
    };
    //-----------------------------------------
    // Start new wession
    //-----------------------------------------
    $session = new Session;
    $session->Hello();
    ?>
    

    【讨论】:

    • 我非常怀疑这是问题所在,除非 OP 使用的是非常过时的 Apache 版本或其他 Web 服务器。
    • 非常感谢您的快速回复 Mr.Prakash Lobo。在我更改会话 php 文件中的代码后,索引页面完全空白。
    • 是的。你是类方法没有返回任何 think.l 已使用名为 Hello() 的新方法更新了答案
    猜你喜欢
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2011-11-11
    • 2021-09-08
    • 2017-12-26
    • 2016-09-27
    相关资源
    最近更新 更多