Skip to content

Instantly share code, notes, and snippets.

/test.php Secret
Created Sep 1, 2016

Embed
What would you like to do?
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBag;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
use Zend\Diactoros\Response\SapiStreamEmitter;
require dirname(__DIR__) . '/vendor/autoload.php';
$factory = new DiactorosFactory();
$sessionHandler = new NativeFileSessionHandler();
$sessionMetadataBag = new MetadataBag('_sf2_meta', '0');
$sessionStorage = new NativeSessionStorage(['cookie_httponly' => true, 'gc_probability' => 1], $sessionHandler, $sessionMetadataBag);
$session = new Session($sessionStorage, new AttributeBag(), new FlashBag());
$session->start();
$foundationResponse = new Response();
if (isset($_GET['set_cookie'])) {
// emulate Symfony authentication
$session->migrate(true);
// emulate Symfony rememberme
$foundationResponse->headers->setCookie(new Cookie('REMEMBERME', 'value', time() + 123456, '/', $_GET['set_cookie']));
}
$response = $factory->createResponse($foundationResponse);
$emitter = new SapiStreamEmitter();
$emitter->emit($response);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.