Skip to content

Commit

Permalink
Close #215: Write session name to file in cmsimple/ folder
Browse files Browse the repository at this point in the history
Whenever a session is started via `XH_startSession()`, we update
cmsimple/.sessionname to contain the current session name. This
simplifies to reuse the CMSimple_XH session in external scripts.
  • Loading branch information
cmb69 committed May 6, 2017
1 parent fe3dec8 commit 07549db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Empty file added cmsimple/.sessionname
Empty file.
6 changes: 5 additions & 1 deletion cmsimple/functions.php
Expand Up @@ -2656,8 +2656,12 @@ class_alias($className, str_replace('\\', '_', $className));
*/
function XH_startSession()
{
global $pth;

if (session_id() == '') {
session_name('XH_' . bin2hex(CMSIMPLE_ROOT));
$sessionName = 'XH_' . bin2hex(CMSIMPLE_ROOT);
file_put_contents("{$pth['folder']['cmsimple']}.sessionname", $sessionName);
session_name($sessionName);
session_start();
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/ControllerTest.php
Expand Up @@ -563,6 +563,7 @@ public function setUp()
$this->logMessageMock = new PHPUnit_Extensions_MockFunction(
'XH_logMessage', $this->subject
);
new PHPUnit_Extensions_MockFunction('file_put_contents', $this->subject);
}

/**
Expand Down Expand Up @@ -714,6 +715,7 @@ public function setUp()
$this->backupMock = new PHPUnit_Extensions_MockFunction(
'XH_backup', $this->subject
);
new PHPUnit_Extensions_MockFunction('file_put_contents', $this->subject);
}

/**
Expand Down

0 comments on commit 07549db

Please sign in to comment.