dougao1542 2017-07-10 14:41
浏览 19
已采纳

在我的电子商务网站购买确认页面显示警告信息[重复]

This question already has an answer here:

I am trying to developing a ecommerce website. But My problem is in product purchase confirmation page.It show this type of message: (Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\online shop\dataAccessLayer\dalSession.php on line 6) I need to some suggestion how can I solve this issue. Here is my code.

This is my dalSession.php page:

<?php

class Session
{
public static function Start(){
    session_start(); //line 6
}

public static function Set($key , $value){
    $_SESSION[$key] = $value;
}

public static function Get($key){
    if (isset($_SESSION[$key])) {
        return $_SESSION[$key];
    }
    else{
        return false;
    }
}

public static function Stop(){
    session_destroy();
    header("Location:user/login.php");
}

public static function StopA(){
    session_destroy();
    header("Location:../user/login.php");
}

public static function StopB(){
    session_destroy();
    header("Location:login.php");
}


public static function Check()
{
    self::Start();
    //echo $this->user_id;;
    if (self::Get("Mlogin")==false) 
    {
        self::Stop();
        header("Location:login.php");
    }
}

public static function CheckA(){
    self::Start();
    if (self::Get("Alogin")==false) {
       self::StopA();
       header("Location:../user/login.php");
    }
}

public static function CheckAll()
{
    if (self::Get("Mlogin")==false && self::Get("Alogin")==false) 
    {
        return false;
    }
    else
    {
        return true;    
    }    
}

public static function CheckUserLogin()
{self::Start();
    if (self::Get("Mlogin")==false) 
    {
        return false;
    }
    else
    {
        return true;    
    }    
}

public static function Auto(){
    self::Start();
    if(self::Get("Mlogin")==false){
       echo "<a style=\"color:white;\" href='user/login.php'>Login</a>";
 } else {
       echo "<a style=\"color:red;\" href='?action=logout'>Logout</a>";
      if(isset($_GET['action']) && ($_GET['action']== "logout")){
        self::Stop();
    }
 }

}

 public static function AutoA(){
    self::Start();
    if(self::Get("Mlogin")==false){
       echo "<a style=\"color:white;\" href='login.php'>Login</a>";
    } else {
       echo "<a style=\"color:red;\" href='?action=logout'>Logout</a>";
      if(isset($_GET['action']) && ($_GET['action']== "logout")){
        self::StopB();
       }
   }

  }


  }

  ?>

This is My confirm.php code:

  <?php
   require_once("/../dataAccessLayer/dalSession.php");
   require_once("/../dataAccessLayer/dalLogin.php");
   session::check();
   ?>

   <?php
    if(isset($_GET['action']) && ($_GET['action']== "logout")){
        Session::Stop();
    }
    ?>
    <!doctype html>
    <html lang="en-US">
    <head>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <title>Success Notification Boxes</title>

   <link rel="stylesheet" type="text/css" media="all" href="style.css">
   <script type="text/javascript" src="https://ajax.googleapis.com          /ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   </head>

  <body>

  <div id="w">
  <div id="content">
  <!-- Icons source http://dribbble.com/shots/913555-Flat-Web-Elements -->
  <div class="notify successbox">
    <h1>Success!</h1>
    <span class="alerticon"><img src="" alt="checkmark" /></span>
    <p>Thanks For Your Purchase.</p>
    <p>Your Purchase Will Deliver Within 72 Hours.</p>
    <p>Any Question? Please Call: <b>+8801721557233</b></p>
    <p></p>
    </div>

    <h1><a class="navbar-brand" href="../index.php">Home</a></h1>


    </div><!-- @end #content -->
    </div><!-- @end #w -->

    </body>
    </html>
</div>
  • 写回答

2条回答 默认 最新

  • donglulong0877 2017-07-10 14:45
    关注

    You can modify your function Start. Replace:

    public static function Start(){
        session_start();
    }
    

    By:

    public static function Start(){
        if (session_status() == PHP_SESSION_NONE) {
            session_start();
        }
    }
    

    It will fix your problem (the notice will not be displayed anymore). The idea is: if your session is already started, don't start it again.

    Then if it does not work, remove ALL the space in your confirm.php file before the first <?php (it seems you have two spaces before the first <?php but I'm not sure it's because you copy/pasted it).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析