Commit d1a6907f authored by Carsten  Rose's avatar Carsten Rose
Browse files

SessionCookie.php: New class to save current cookies in a file.

parent 45b2e9a7
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 4/30/17
* Time: 1:45 PM
*/
namespace qfq;
require_once(__DIR__ . '/../Constants.php');
class SessionCookie {
private $pathFileNameCookie = '';
/**
* Copy all current cookies to a temporary file.
*
* @param string $domain
* @param string $path
* @throws CodeException
*/
public function __construct($domain, $path) {
$lines = '';
$this->pathFileNameCookie = tempnam(sys_get_temp_dir(), SESSION_COOKIE_REFEIX);
if (false === $this->pathFileNameCookie) {
throw new CodeException('Error creating output file.', ERROR_IO_CREATE_FILE);
}
foreach ($_COOKIE as $name => $value) {
// e.g.: SANDBOXSESSION=a83f1o69jbv12932q54hmgphk6; domain=qfq.math.uzh.ch; path=/;
$lines .= $name . "=" . $value . "; domain=$domain; path=$path;\n";
}
file_put_contents($this->pathFileNameCookie, $lines, FILE_APPEND);
}
/**
* Unlink current cookie file
*/
public function __destruct() {
if (file_exists($this->pathFileNameCookie)) {
unlink($this->pathFileNameCookie);
$this->pathFileNameCookie = '';
}
}
/**
* @return string PathFilename of cookie file
*/
public function getFile() {
return $this->pathFileNameCookie;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment