我正在使用下面的代码,它似乎工作正常,但我似乎无法更改cookie名称。它总是默认为PHPSESSID有没有人有任何想法我错了?
由于
//Enable composer based autoloading
require './vendor/autoload.php';
class_alias('Cartalyst\Sentry\Facades\Native\Sentry', 'Sentry');
$hasher = new Cartalyst\Sentry\Hashing\NativeHasher; // There are other hashers available, take your pick
$userProvider = new Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
$groupProvider = new Cartalyst\Sentry\Groups\Eloquent\Provider;
$throttleProvider = new Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
$session = new Cartalyst\Sentry\Sessions\NativeSession;
// Note, all of the options below are, optional!
$options = array(
'name' => 'cartalyst_sentry', // Default "cartalyst_sentry"
'time' => null, // Default 300 seconds from now
'domain' => null, // Default ""
'path' => null, // Default "/"
'secure' => null, // Default "false"
'httpOnly' => null, // Default "false"
);
$cookie = new Cartalyst\Sentry\Cookies\NativeCookie($options);
$sentry = new Sentry(
$userProvider,
$groupProvider,
$throttleProvider,
$session,
$cookie
);
// Setup our database
$dsn = 'mysql:dbname=database;host=localhost';
$user = 'root';
$password = 'password';
$sentry::setupDatabaseResolver(new PDO($dsn, $user, $password));
try
{
// Set login credentials
$credentials = array(
'email' => 'email@gmail.com',
'password' => 'password',
);
// Try to authenticate the user
$user = $sentry::authenticate($credentials, false);
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
{
echo 'Login field is required.';
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
{
echo 'Password field is required.';
}
catch (Cartalyst\Sentry\Users\WrongPasswordException $e)
{
echo 'Wrong password, try again.';
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
echo 'User was not found.';
}
catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
{
echo 'User is not activated.';
}
// The following is only required if throttle is enabled
catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
{
echo 'User is suspended.';
}
catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
{
echo 'User is banned.';
}
if ($sentry::check())
{
echo 'User logged in.';
}
答案 0 :(得分:0)
Cartalyst \ Sentry \ Sessions \ NativeSession无法更改会话的Cookie名称(至少如果这是正确的类:https://github.com/cartalyst/sentry/blob/master/src/Cartalyst/Sentry/Sessions/NativeSession.php)。
您可以在会话开始前调用session_name('cookie_name_here')
来设置自己。最简单的方法是在<?php
之后。试试它是否适用于那里。