Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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会话编辑器_Php_Debugging_Session - Fatal编程技术网

PHP会话编辑器

PHP会话编辑器,php,debugging,session,Php,Debugging,Session,有没有工具可以让我编辑$\u会话的内容?我正在尝试调试一个依赖于会话状态的脚本,我只希望能够更改会话变量,而不必更改数据库、销毁会话并重新创建它。在给定的时间内,我可能会构建一个特别的会话编辑器,但目前我没有多余的时间 那么,$\u SESSION中的信息只是作为序列化字符串存储在磁盘上。(如果不使用memcached会话存储) 因此,读入该文件,对其内容进行非序列化,更改适当的值,然后将其序列化回来,应该是您所需要的一切 如果不想处理此问题,可以在会话开始()之前设置会话id(),然后使用p

有没有工具可以让我编辑$\u会话的内容?我正在尝试调试一个依赖于会话状态的脚本,我只希望能够更改会话变量,而不必更改数据库、销毁会话并重新创建它。在给定的时间内,我可能会构建一个特别的会话编辑器,但目前我没有多余的时间

那么,
$\u SESSION
中的信息只是作为序列化字符串存储在磁盘上。(如果不使用memcached会话存储)

因此,读入该文件,对其内容进行非序列化,更改适当的值,然后将其序列化回来,应该是您所需要的一切


如果不想处理此问题,可以在
会话开始()之前设置
会话id()
,然后使用php编辑值,然后调用
会话写入关闭()
将其再次存储在磁盘上


会话id的示例脚本:

<?php

session_id("838c4dc18f6535cb90a9c2e0ec92bad4");
session_start();
var_dump($_SESSION);
$_SESSION["a"] = "foo";
session_write_close();

有什么工具可以让我编辑$\u会话的内容吗

查看您的会话

设置您的会话


您通常希望var_转储会话,以便在调试会话时查看它是什么。

如Col.Shrapnel所述,我只需在相同的服务器上设置一个新的PHP脚本,如下所示:

<?php
session_start();
$_SESSION['key'] = 'value'; // repeat for every value you need to change

非常基本的会话编辑器的源代码(是的,找到了一点时间来实际使用)


会话编辑器
标签{
显示:内联块;
最小宽度:8em;
文本对齐:右对齐;
右侧填充:.3em;
}
会话编辑器

如果您使用

稍微扩展它,也可以在调试会话中实时执行,只需添加添加新会话变量的功能:

<?php

function listData (array $data, array $parents = array ())
{
    $output = '';
    $parents    = array_map ('htmlspecialchars', $parents);
    $fieldName  = $parents?
        '[' . implode ('][', $parents) . ']':
        '';
    foreach ($data as $key => $item)
    {
        $isArr  = is_array ($item);
        $output .= $isArr?
            '<li><h4>' . htmlspecialchars ($key) . '</h4>':
            '<li><label>' . htmlspecialchars ($key) . '</label>: ';
        $output .= $isArr?
            '<ul>' . listData ($item, array_merge ($parents, array ($key))) . '</ul>': 
            '<input type="text" name="fields' . $fieldName . '[' . htmlspecialchars ($key) . ']" value="' . htmlspecialchars ($item) . '" />';
        $output .= "</li>\n";
    }
    return ($output);
}

session_start ();

if ($_POST ['fields'])
{
    $_SESSION   = $_POST ['fields'];
    session_commit ();
}

if ($_POST['newfield'])
{
    $_SESSION[$_POST['newfield']] = $_POST['newfieldvalue'];
    session_commit ();
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Session Editor</title>
        <style type="text/css">
        label {
            display: inline-block;
            min-width: 8em;
            text-align: right;
            padding-right: .3em;
        }
        </style>
    </head>
    <body>
        <h2>Session Editor</h2>
        <form action="<?php echo ($_SERVER ['SCRIPT_NAME']); ?>" method="post">
            <ul>
                <?php echo (listData($_SESSION)); ?>
            </ul>
            <div>
                <input type="submit" />
            </div>
        </form>
        -------------------------
        <form action="<?php echo ($_SERVER ['SCRIPT_NAME']); ?>" method="post">
            New Session Var:<input type="text" name="newfield" /><br />
            Session Var Value:<input type="text" name="newfieldvalue" />
            <div>
                <input type="submit" />
            </div>
        </form>


    </body>

</html>

会话编辑器
标签{
显示:内联块;
最小宽度:8em;
文本对齐:右对齐;
右侧填充:.3em;
}
会话编辑器

一个开源项目的好主意!我不认为序列化和非序列化是必要的,编辑器应该能够启动会话,进行更改,然后在执行任何实际输出之前提交会话。不过基本的方法看起来不错。我补充说,在这种情况下,您希望更改许多会话,而不是“会话启动/打开”每个会话:)这是个好主意,但现在我只需要编辑我超现实地连接到的会话。这是我一直在做的事情,但这并不是一个很好的方法。每次我想更改会话变量时都要编辑代码是浪费时间。如果我可以启动一个web应用程序并在其中编辑会话,那会更好。我看不出这比打开编辑器并以这种方式进行更改要快多少。也许你不用在必要的时候在浏览器窗口中执行脚本。不知道是谁否决了你。这就是我到目前为止一直在使用的方法,我只是希望这里会有一些开源编辑器,而不需要为我想要调试的每一个会话状态都编写新代码。+1和我的感谢,因为这正是我想要的
var_dump( $_SESSION );
$_SESSION['variabletoset'] = 'value';
<?php
session_start();
$_SESSION['key'] = 'value'; // repeat for every value you need to change
<?php

function listData (array $data, array $parents = array ())
{
    $output = '';
    $parents    = array_map ('htmlspecialchars', $parents);
    $fieldName  = $parents?
        '[' . implode ('][', $parents) . ']':
        '';
    foreach ($data as $key => $item)
    {
        $isArr  = is_array ($item);
        $output .= $isArr?
            '<li><h4>' . htmlspecialchars ($key) . '</h4>':
            '<li><label>' . htmlspecialchars ($key) . '</label>: ';
        $output .= $isArr?
            '<ul>' . listData ($item, array_merge ($parents, array ($key))) . '</ul>': 
            '<input type="text" name="fields' . $fieldName . '[' . htmlspecialchars ($key) . ']" value="' . htmlspecialchars ($item) . '" />';
        $output .= "</li>\n";
    }
    return ($output);
}

session_start ();

if ($_POST ['fields'])
{
    $_SESSION   = $_POST ['fields'];
    session_commit ();
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Session Editor</title>
<style type="text/css">
label {
    display: inline-block;
    min-width: 8em;
    text-align: right;
    padding-right: .3em;
}
</style>
</head>
<body>
    <h2>Session Editor</h2>
    <form action="<?php echo ($_SERVER ['SCRIPT_NAME']); ?>" method="post">
        <ul>
        <?php echo (listData ($_SESSION)); ?>
        </ul>
        <div>
            <input type="submit" />
        </div>
    </form>
</body>
</html>
<?php

function listData (array $data, array $parents = array ())
{
    $output = '';
    $parents    = array_map ('htmlspecialchars', $parents);
    $fieldName  = $parents?
        '[' . implode ('][', $parents) . ']':
        '';
    foreach ($data as $key => $item)
    {
        $isArr  = is_array ($item);
        $output .= $isArr?
            '<li><h4>' . htmlspecialchars ($key) . '</h4>':
            '<li><label>' . htmlspecialchars ($key) . '</label>: ';
        $output .= $isArr?
            '<ul>' . listData ($item, array_merge ($parents, array ($key))) . '</ul>': 
            '<input type="text" name="fields' . $fieldName . '[' . htmlspecialchars ($key) . ']" value="' . htmlspecialchars ($item) . '" />';
        $output .= "</li>\n";
    }
    return ($output);
}

session_start ();

if ($_POST ['fields'])
{
    $_SESSION   = $_POST ['fields'];
    session_commit ();
}

if ($_POST['newfield'])
{
    $_SESSION[$_POST['newfield']] = $_POST['newfieldvalue'];
    session_commit ();
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Session Editor</title>
        <style type="text/css">
        label {
            display: inline-block;
            min-width: 8em;
            text-align: right;
            padding-right: .3em;
        }
        </style>
    </head>
    <body>
        <h2>Session Editor</h2>
        <form action="<?php echo ($_SERVER ['SCRIPT_NAME']); ?>" method="post">
            <ul>
                <?php echo (listData($_SESSION)); ?>
            </ul>
            <div>
                <input type="submit" />
            </div>
        </form>
        -------------------------
        <form action="<?php echo ($_SERVER ['SCRIPT_NAME']); ?>" method="post">
            New Session Var:<input type="text" name="newfield" /><br />
            Session Var Value:<input type="text" name="newfieldvalue" />
            <div>
                <input type="submit" />
            </div>
        </form>


    </body>

</html>