本地主机XAMPP服务器上的PHP会话过期错误,但当我在远程上上传项目时,没有错误


PHP session expired error on localhost XAMPP server but when i upload the project on remoter it's working without error

你好,如果有人能帮我解决这个问题,我将不胜感激。我花了将近三天的时间试图解决这个问题,但还是没有成功。

我的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
?>

更新:我已经用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();
?>