2016-12-30 78 views
0

如何傳遞多個$_session一個頁面,不同的價值 有一個頁面action.phpindex.php,其中index.php提交action.php和錯誤消息將在$_SESSION店,但我只能通過$_session這裏的index.php的一個是我的index.php我如何將多個seession傳遞到一個頁面在PHP

<?php 
session_start(); 
include_once 'dbconnect.php'; 

if (isset($_SESSION['userSession'])!="") { 
    //header("Location: home.php"); 
} 
error_reporting(0); 

$Loginmsg = $_SESSION['LoginMsg']; 
$_SESSION['LoginMsg'] = ""; 
extract($_POST); 

?> 
<!DOCTYPE html> 
<html> 

<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <title>Dashboard</title> 

    <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> 
    <!-- Tell the browser to be responsive to screen width --> 
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> 
    <!-- Bootstrap 3.3.5 --> 
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css"> 
    <!-- Theme style --> 
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css"> 

    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css"> 

    <!--jquery--> 
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script> 

    <link rel="stylesheet" href="dist/css/summernote.css"> 
    <script src="dist/js/summernote.js"></script> 

</head> 

<body class="hold-transition skin-blue sidebar-mini"> 
    <div class="wrapper"> 
     <header class="main-header"> 
      <!-- Logo --> 
      <a href="#" class="logo"> 
       <!-- mini logo for sidebar mini 50x50 pixels --> 
       <span class="logo-mini"><b>A</b>LT</span> 
       <!-- logo for regular state and mobile devices --> 
       <span class="logo-lg"><b>Administrator</b></span> 
      </a> 
      <!-- Header Navbar: style can be found in header.less --> 
      <nav class="navbar navbar-static-top" role="navigation"> 
       <!-- Sidebar toggle button--> 
       <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"> 
        <span class="glyphicon glyphicon-menu-hamburger"></span> 
       </a> 
      </nav> 
     </header> 
     <?php if ($Loginmsg != "") { 
       echo '<center><div class="alert alert-success" role="alert">' . $Loginmsg . '</div></center>'; 

       } ?> 
     <!-- Left side column. contains the logo and sidebar --> 
     <?php include'menu.php'; ?> 
      <!-- Content Wrapper. Contains page content --> 
      <div class="content-wrapper"> 
       <!-- Content Header (Page header) --> 

       <!-- Main content --> 
       <section class="content"> 
        <?php 
      if(isset($_GET['page'])) 
      { 
      switch($_GET['page']) 
      { 

       case 'berita': include'form_b.php'; break; 
       case 'users': include'users.php'; break;      
       case 'media': include'media.php'; break; 
       case 'edit': include'edit.php'; break; 
       case 'slider': include'slider.php'; break;     
       case 'list_berita': include'list_berita.php';$order=3; break; 

      } 
      } 
     ?> 
       </section> 
      </div> 
      <!-- /.content-wrapper --> 
      <footer class="main-footer"> 
       <div class="pull-right hidden-xs"> 
        <b>Version</b> 2.3.0 
       </div> 
       <strong>Copyright &copy; 2015<a href="http://dtc-eng.blogspot.co.id/">Detailed Technology Center</a>.</strong> All rights reserved. 
      </footer> 
      <div class="control-sidebar-bg"></div> 
    </div> 
    <!-- ./wrapper --> 
    <!-- Bootstrap 3.3.5 --> 
    <script src="../bootstrap/js/bootstrap.min.js"></script> 
    <script> 
     $(document).ready(function() { 
      $('.konten').summernote({ 
       height: 300, // set editor height 
       minHeight: null, // set minimum height of editor 
       maxHeight: null, // set maximum height of editor 
       focus: true, // set focus to editable area after initializing summernote 
       toolbar: [ 
        ['style', ['style']], 
        ['font', ['bold', 'italic', 'underline', 'clear']], 
        ['fontname', ['fontname']], 
        ['color', ['color']], 
        ['para', ['ul', 'ol', 'paragraph']], 
        ['height', ['height']], 
        ['table', ['table']], 
        ['insert', ['link', 'hr']], 
        ['view', ['fullscreen', 'codeview']] 
       ], 

       onPaste: function (e) { 
        var bufferText = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text'); 
        e.preventDefault(); 
        setTimeout(function() { 
         document.execCommand('insertText', false, bufferText); 
        }, 10); 
       } 



      }); 


     }); 
    </script> 
    <script src="plugins/datatables/jquery.dataTables.min.js"></script> 
    <script src="plugins/datatables/dataTables.bootstrap.min.js"></script> 
    <script> 
     $(function() { 
      $("#example1").DataTable({ 
       "order": [[<?php echo $order; ?>, "desc"]] 
      }); 
     }); 
    </script> 
    <script> 
     $.widget.bridge('uibutton', $.ui.button); 
    </script> 
    <!-- Sparkline --> 
    <script src="plugins/sparkline/jquery.sparkline.min.js"></script> 
    <!-- jvectormap --> 
    <script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script> 
    <script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script> 
    <!-- jQuery Knob Chart --> 
    <script src="plugins/knob/jquery.knob.js"></script> 
    <!-- daterangepicker --> 
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script>--> 
    <script src="plugins/daterangepicker/daterangepicker.js"></script> 
    <!-- datepicker --> 
    <script src="plugins/datepicker/bootstrap-datepicker.js"></script> 
    <!-- Slimscroll --> 
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script> 
    <!-- FastClick --> 
    <script src="plugins/fastclick/fastclick.min.js"></script> 
    <!-- AdminLTE App --> 
    <script src="dist/js/app.min.js"></script> 
    <!-- AdminLTE dashboard demo (This is only for demo purposes) --> 
    <script src="dist/js/pages/dashboard.js"></script> 
    <!-- AdminLTE for demo purposes --> 
    <script src="dist/js/demo.js"></script> 
    <script> 
     $('#tgl_agenda').datepicker({ 
      format: 'dd-mm-yyyy' 
     }) 
    </script> 

</body> 
</html> 

與上面的代碼的問題是,我只能通過session傳遞一個錯誤信息我怎麼可以讓它像我想用不同的值

+1

在會話中傳遞數組 –

+0

添加像逗號分隔或使用「:」添加任何模式會話,然後解析每個值你想要的地方 –

回答

2

會話可以像數組一樣使用。您不會將單個變量傳遞給單個頁面。通過會話,您可以在任何頁面上保存和檢索數據。

你需要確保在每個頁面的頂部啓動會話:

session_start(); 

,如果你正在處理錯誤,你可以創建一個子數組包含所有的人:

$_SESSION['errors'] = array(); 

// If there's an error 
if ($error) { 
    // Add error to array 
    $_SESSION['errors'][] = $error; 
} 

// Check if there are errors 
if (is_array($_SESSION['errors']) && count($_SESSION['errors']) != 0) { 
    foreach ($_SESSION['errors'] as $error) { 
     echo $error."<br />"; 
    } 
} 

好運氣!

1
<?php 
    session_start(); 
    //Creating session array to store multiple session values 
    $_SESSION['errors'] = array(); 
    //Value1 
    $sessionvalue1=$_SESSION['userSession']; 
    //Value 2 
    $_SESSION['errors'][$sessionvalue1]="Value 1"; 
    $_SESSION['errors']['error2']="Value 2"; 
?> 
相關問題