Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我无法获取COOKIE来更新它';s值(是一个整数)_Php_Cookies - Fatal编程技术网

Php 我无法获取COOKIE来更新它';s值(是一个整数)

Php 我无法获取COOKIE来更新它';s值(是一个整数),php,cookies,Php,Cookies,我已经做了这么长时间了,我觉得这是我的最后一个选择,我有一个html网页上的幻灯片,他们基本上可以通过滚动浏览到最后。基本上,我希望用户能够返回到他们的仪表板,当他们点击返回到幻灯片时,重新加载他们所在的页面 在页面顶部,我有以下内容: <?php if (!isset($_COOKIE['PageNo'])){ setcookie("PageNo", 1, time() + (86400 * 30), "/"); // 86400 = 1 day, so set th

我已经做了这么长时间了,我觉得这是我的最后一个选择,我有一个html网页上的幻灯片,他们基本上可以通过滚动浏览到最后。基本上,我希望用户能够返回到他们的仪表板,当他们点击返回到幻灯片时,重新加载他们所在的页面

在页面顶部,我有以下内容:

    <?php
  if (!isset($_COOKIE['PageNo'])){
    setcookie("PageNo", 1, time() + (86400 * 30), "/"); // 86400 = 1 day, so set the cookie for a month long period
  }
?>

我的意思是,首先将cookie设置为1(幻灯片中的第一页=1,然后在下一节的上方我有以下内容:

<?php

    if($_COOKIE['PageNo'] >= 2) 
  {
    ?>

    <script>
      window.location.replace("<?php echo "istudy_university.php#slide=".$_COOKIE['PageNo']; ?> ");
    </script>

<?php
  }
    else
  { 
?>
  <script>
      window.location.replace("istudy_university.php#slide=1");
  </script>
<?php
  }
?>

窗口。位置。替换(“”);
window.location.replace(“istudy_university.php#slide=1”);
在每张幻灯片上方,我有以下内容,只需更改幻灯片=编号:

<?php $_COOKIE['PageNo'] = 3; ?>

所以我的意思是,如果cookie大于或等于2,那么转到no'x'页,或者转到第1页。但是,它一直在做的就是让我不断回到第1页。请帮助!!我设置cookie错误了吗

更新:在浏览了一些幻灯片之后,cookie应该已经更改为5,但是它仍然是1

显示页面HTML的更新代码:


iStudy大学|压力与焦虑
窗口。位置。替换(“”);
window.location.replace(“istudy_university.php#slide=1”);
压力与焦虑




伊斯图迪大学 由学生设计
IV
学生

“没有人能在你的内心制造消极或压力。只有你能通过处理你的世界来做到这一点”

韦恩·戴尔

压力与焦虑 压力和焦虑是高等教育学生的常见经历。
本模块将向您介绍基于认知行为疗法(CBT)的管理压力和焦虑的循证技术


在仪表板和幻灯片页面中包括jQuery库。 在幻灯片页面中包括库

在仪表板页面中,向幻灯片页面导航链接添加id,如:

<a  id="home" href="#">Slides</a>
在仪表板页面的末尾,将以下JavaScript代码添加到页脚:

 <script>
      if(localStorage.getItem('currentPage') != ''){
          var newUrl = 'scroll.html#'+localStorage.getItem('currentPage');
        $("#home").attr("href", newUrl);
      }
    </script>

if(localStorage.getItem('currentPage')!=“”){
var newUrl='scroll.html#'+localStorage.getItem('currentPage');
$(“#home”).attr(“href”,newUrl);
}

cookie是否已保存?能否通过浏览器检查或转储
$\u cookie['PageNo'确认其值
。在PHP中设置cookie可能会有点混乱,看看这里的文档和示例它们可能有帮助hi@Script47当我查看页面源代码时,cookie编号始终为1。为了测试它是否有效,我将
放在PHP代码的最顶端,它确实直接将我带到了第5页,但是当n我将cookie设置在每张幻灯片上方,但它不起作用:(@t.C您似乎没有增加$u cookie['PageNo']值。Hello@Akshithdayana,我只是为每张幻灯片自动设置它,即在我放置的一张幻灯片上方,然后下一张幻灯片的顶部有这个,依此类推?每次我回到主页,然后回到幻灯片,它应该记得我在哪个编号的幻灯片上(如果cookie已保存,ok),但它直接返回到1。我的连接是否可能做得不正确(@T.C即使使用上面的coed而不是每张幻灯片上面的coed来更新cookie,您是否也面临这个问题?因此,我将它放在每个部分的顶部,
,它仍然让我想起1@T.C是否在主页中设置任何cookie值?如果需要,请显示主页代码caould@T.C哈哈..我会尝试更新my代码让您开始
<section class="slides aligncenter" id="b">
        <span class="background light" style="background-image: url('istudy_slides_images/mountain.jpg')" /></span>
        <div class="wrap" id="slide=2">
            <blockquote class="quote">
                <p class>"No one can create negativity or stress within you. Only you can do that by virtue of how you process your world"</p>
                <p><cite>Wayne Dyer</cite></p>
            </blockquote>
        </div>
    </section>
    <!-- SLIDE 3 -->
    <section class="slides bg-slide3" id="c">
        <div class="wrap size-80" id="slide=3">
            <h3 class="title stessAnx"><strong>&ensp;Stress & Anxiety</strong></h3><br>
            <p>Stress and anxiety are common experiences of students in higher education.<br>This module will introduce you to evidence based techniques for managing stress and anxiety based upon cognitive behavioural therapy (CBT).</p>
    </section>
$.scrollify({
    section: ".slides", //Rename the class name with the common class name that you gave for the sections
    after: function() {

        localStorage.setItem('currentPage', $.scrollify.current()[0].id)

    }
});
 <script>
      if(localStorage.getItem('currentPage') != ''){
          var newUrl = 'scroll.html#'+localStorage.getItem('currentPage');
        $("#home").attr("href", newUrl);
      }
    </script>