【问题标题】:maintaining session in directory traversal using php使用php在目录遍历中维护会话
【发布时间】:2011-09-27 21:33:13
【问题描述】:

我是 php 新手...我正在尝试在目录遍历脚本中维护会话...但是每次我转到子目录时,我的会话变量都会丢失...
现在我的脚本看起来像 -

start_session();          

//login and authenticate using functions in included scripts 
//(include(login.php);include(auth.php)) and set session variables accordingly  

if (session variable is set)
{
    //start the traversal script
}  

所以我想知道的是如何在目录遍历中管理会话 .... 任何人都可以在这里帮助我...

【问题讨论】:

  • 如果您将脚本的结构摘要作为代码参考粘贴到您的帖子中(包括与您的问题相关的会话访问),会更容易。
  • 您必须确保在转到子目录时保留会话 ID(我假设这意味着调用另一个脚本)。确保会话 id 作为 get-variable 传递,或者更好的是作为 cookie 传递。 cf php.net/session
  • thx wonk0 但我没有调用另一个脚本来转到子目录......事实上,我使用指定目录的查询字符串递归调用相同的脚本('?dir ='。目录名称)......当我在查询字符串本身中传递一个标志变量时,我可以使代码工作,但是当我尝试将它存储在会话变量中时它会丢失......

标签: php


【解决方案1】:

http://www.php.net/manual/en/function.session-start.php

session_start();

if (isset($_SESSION['directory_path'])) {
   $directory_path = $_SESSION['directory_path'];
} else {
   $directory_path = 'default/path';
}

// traverse with path

$_SESSION['directory_path'] = $new_directory_path;

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多