duanlachu7344 2014-10-06 09:03
浏览 63
已采纳

是否可以添加session_start(); 到我整个网站的顶部?

I've been using the following code in our buying process section of our website by placing at the top of each stage where sessions are used.

   <?php
    session_cache_limiter('private_no_expire'); // must go before session start
    session_start();

I want to start using sessions more widely on the website, for instance in the customer login area.

I have a file called "all.php" which includes all my classes/objects and shared includes at the start of each page on my system. I thought removing the above code from all the separate e-commerce files and adding to the top of "all.php" would be a good idea seeing as it's system wide, and the first thing that loads on the page.

Since doing this, my customer login area has encountered problems. It keeps throwing users back to the login page after they've navigated a few links. It seems when you hit a URL that you've already been on it doesn't like it and just sends you back to the start. If you add &1=1 onto a url that you've been onto before, it tricks the system into letting you visit the page because its a new unique url. So the cache is definitely messing up.

I'm not actually using sessions in this section of the website yet so it's not like you are actually being logged out... it's just sending you to that page where you started,

Can anyone shed any light on what may be going wrong here?

Could it be my use of session_cache_limiter('private_no_expire');

I use the above line because my buying process uses POST forms and clicking the back button gave ugly messages about data being resubmitted.

http://php.net/manual/en/function.session-cache-limiter.php

UPDATE:

Commenting out that first line has helped and the issue has stopped:

//session_cache_limiter('private_no_expire'); // must go before session start

It's a temporary fix as this means the back button is causing data resubmission warnings. That just means I need to implementing this properly but I'd still ike to understand why that line is doing that:

http://en.wikipedia.org/wiki/Post/Redirect/Get

  • 写回答

2条回答 默认 最新

  • doujiang2812 2014-10-06 11:35
    关注

    This is the similar thing as we create a login panel in PHP. As soon as user is loged in you need to start the session by using session_start() and when the user click log out stop the session by using ssession_unset(). This will solve you issues. Try it out and let me know if it works.

    Keep Coding..

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

报告相同问题?

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败