为什么SESSION总值1? [英] Why in SESSION always value 1?
本文介绍了为什么SESSION总值1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1 <?php
2
3 if (!defined('BASEPATH')) exit('Нет доступа к скрипту');
4 session_start();
5 class Banners
6
7 {
8 private $core;
9 public $on = TRUE;
10 private $shows = 2;
11 public $banners = array();
12 public $array_shows = array();
13 public $positions = array();
14
15
16
17
18 function __construct()
19 {
20
21 $this->core = $CI = & get_instance();
22 //unset($_SESSION['BANNERS']); die();
23 $this->Check();
24 $this->GetAllBanners();
25
26
27 }
28
29 protected function Check()
30 {
31 if (empty($_SESSION['BANNERS']) && $this->on == TRUE)
32 {
33
34 $_SESSION['BANNERS'] = $this->Get();
35
36 }
37 }
38
39 public function GetAllBanners(){
40
41 foreach ($_SESSION['POSITIONS'] as $position) {
42
43 $this->GetCurrentBanner($position);
44 }
45 }
46
47
48 public function Get()
49 {
50 $query = $this->core->db->query('SELECT * FROM banners WHERE status = 1 AND showes>0 AND timeout >= CURDATE() ORDER BY position DESC')->result();
51 return $this->SortList($query);
52 }
53
54 private function SortList($array)
55 {
56 foreach($array as $value)
57 {
58
59 $this->banners[$value->position]['id'][] = $value->id;
60 $this->banners[$value->position]['image'][] = $value->image;
61 $this->banners[$value->position]['code'][] = $value->code;
62 $this->banners[$value->position]['link'][] = $value->link;
63 $this->banners[$value->position]['showes'][] = $value->showes;
64 $this->array_shows[$value->id] = $this->shows;
65 $this->positions[$value->position] = $value->position;
66
67
68 }
69 $_SESSION['POSITIONS'] = $this->positions;
70 $_SESSION['SHOWS'] = $this->array_shows;
71
72 return $this->banners;
73 }
74
75 private function GetCurrentBanner($id_position, $i = 0){
76 echo $_SESSION['SHOWS'][$first_banner]; //HERE GET 1 ALWAYS
77 $first_banner = $_SESSION['BANNERS'][$id_position]['id'][$i];
78
79 if ($_SESSION['SHOWS'][$first_banner] !== 0){
80
81 $int = $_SESSION['SHOWS'][$first_banner] - 1;
82 $_SESSION['SHOWS'][$first_banner] = $int;
83 //HERE GET 0
84 $_SESSION['BANNERS'][$id_position]['showes'][$i] = ($_SESSION['BANNERS'][$id_position]['showes'][$i]) - 1;
85
86
87 $this->banners[$id_position] = array(
88
89 'id' => $_SESSION['BANNERS'][$id_position]['id'][$i],
90 'image' => $_SESSION['BANNERS'][$id_position]['image'][$i],
91 'code' => $_SESSION['BANNERS'][$id_position]['code'][$i],
92 'link' => $_SESSION['BANNERS'][$id_position]['link'][$i]);
93
94
95 } else {
96
97 if($_SESSION['BANNERS'][$id_position]['showes'][$i] !== 0) {
98
99 array_push($_SESSION['SHOWS'], $_SESSION['SHOWS'][$first_banner] = $this->shows);
100
101 }
102 array_shift($_SESSION['SHOWS']);
103 $this->GetCurrentBanner($id_position, $i++);
104
105 }
106
107 }
108
109 }
110 ?>
重新加载页面后调用函数 GetCurrentBanner
并检查会话!== 0
。但在上次重新加载页面后,我的 $ _ SESSION [''SHOWS'']
等于 0(// comment)
,为什么下次重新加载会话后再次为1?
After reload page is called function GetCurrentBanner
and check Session for !==0
. But after last reload page my $_SESSION[''SHOWS'']
was equal 0 (//comment)
, why after next reload Session again is 1?
推荐答案
core ;
9 public
core; 9 public
on = TRUE;
10 private
on = TRUE; 10 private
显示 = 2 跨度>;
11 public
shows = 2; 11 public
这篇关于为什么SESSION总值1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文