Skip to content

Instantly share code, notes, and snippets.

/test.php Secret

Created September 1, 2016 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/88e52bd7876378b0f490ed15d30b43fe to your computer and use it in GitHub Desktop.
Save anonymous/88e52bd7876378b0f490ed15d30b43fe to your computer and use it in GitHub Desktop.
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