本文整理汇总了PHP中Cookie::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::create方法的具体用法?PHP Cookie::create怎么用?PHP Cookie::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie::create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCookieCollection
/**
* @expectedException WrongStateException
*/
public function testCookieCollection()
{
if (!isset($_SERVER["DOCUMENT_ROOT"]) || !$_SERVER["DOCUMENT_ROOT"]) {
$this->markTestSkipped('can\'t test cookies without web');
}
echo "";
CookieCollection::create()->add(Cookie::create('anotherTestCookie')->setValue('testValue')->setMaxAge(60 * 60))->httpSetAll();
}
示例2: attempt
public static function attempt($array, $remember = false)
{
//Table::show(self::$hashedFields);
//
$hashed = array();
//
foreach ($array as $key => $value) {
if (Table::contains(self::$hashedFields, $key)) {
Table::add($hashed, Hash::make($array[$key]), $key);
}
}
//
//Table::show($hashed);
//
$where = "";
$ok = false;
//
$i = 0;
foreach ($array as $key => $value) {
if ($i > 0) {
$where .= " and ";
}
if (Table::contains(self::$hashedFields, $key)) {
$where .= "{$key}='" . $hashed[$key] . "' ";
} else {
$where .= "{$key}='{$value}' ";
}
$i++;
}
$sql = "select * from " . self::$table . " where " . $where;
//echo $sql;
//
if (Database::countS($sql) > 0) {
//returning true value
$ok = true;
//
// session
$user = Database::read($sql);
$saved = Config::get('auth.saved_fields');
//
$static = array();
//
foreach ($user[0] as $key => $value) {
if (array_key_exists($key, $saved)) {
$static[$key] = $value;
}
}
//
Session::put('auths', $static);
//
// remember cookie
if ($remember) {
Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7);
}
}
//
return $ok;
}
示例3: modify
/**
* @param RequestInterface $request
* @param string $name
* @param callable $modify
*
* @return RequestInterface
*/
public static function modify(RequestInterface $request, $name, $modify)
{
if (!is_callable($modify)) {
throw new InvalidArgumentException('$modify must be callable.');
}
$cookies = Cookies::fromRequest($request);
$cookie = $modify($cookies->has($name) ? $cookies->get($name) : Cookie::create($name));
return $cookies->with($cookie)->renderIntoCookieHeader($request);
}
示例4: doRun
function doRun()
{
$msg = '';
$username = mysql_real_escape_string($_POST['name']);
$pass = mysql_real_escape_string($_POST['pass']);
try {
$db = new PDO('mysql:host=localhost;dbname=testData', 'root', 'root');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare(' SELECT
username, pass
FROM
testTable
WHERE
username = :name
AND
pass = :pass
');
$stmt->bindParam(':name', $username, PDO::PARAM_STR);
$stmt->bindParam(':pass', $pass, PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result == false) {
$msg = 'sorry could not connect';
} else {
//$_SESSION['name'] = $username;
/**
* Create a cookie with the name "myCookieName" and value "testing cookie value"
*/
$cookie = new Cookie();
// Set cookie name
$cookie->setName('Login');
// Set cookie value
$cookie->setValue("testing cookie value");
// Set cookie expiration time
$cookie->setTime("+1 hour");
// Create the cookie
$cookie->create();
// Delete the cookie.
//$cookie->delete();
$msg = 'logged in as ' . $username . '<br>';
}
} catch (PDOException $e) {
echo "Error:" . $e;
}
echo $msg;
$db = NULL;
}
示例5: provideGetsCookieByNameData
public function provideGetsCookieByNameData()
{
return [['theme=light', 'theme', Cookie::create('theme', 'light')], ['theme=', 'theme', Cookie::create('theme')], ['hello=world; theme=light; sessionToken=abc123', 'theme', Cookie::create('theme', 'light')], ['hello=world; theme=; sessionToken=abc123', 'theme', Cookie::create('theme')]];
}
示例6: get_user_data
// Check to see if the user is already logged in
if ($cookie_handler->cookie_exists("compsec")) {
print "Error: Cannot log in if user is already logged in!";
} else {
// Check to see if the user is already in the database.
// The function will return an array if they are.
$results = get_user_data($uuid);
if (is_array($results)) {
$uuid = $results[1];
$database_password = $results[2];
$salt = $results[3];
// Validate that the supplied password is correct
$hashed_password = hash("sha512", $password . $salt);
if ($database_password == $hashed_password) {
// Store cookie on client's computer
$cookie = Cookie::create($uuid, $hashed_password);
$result = $cookie_handler->set_cookie("compsec", $cookie);
if ($result == false) {
print "An unexpected error has prevented you from logging in. Reason: Unable to create a login cookie.";
}
// Login successful
update_last_login($uuid);
header("location:index.php");
} else {
print "Error: Invalid password. Press the back button to try again.";
}
} else {
print "Error: User does not exist! Press the back button to try again.";
}
}
?>
示例7: setDefault
public static function setDefault()
{
Cookie::create(self::getName(), Config::get('lang.default'), 60 * 24 * 7);
Res::stsession("Fiesta_lang", Config::get('lang.default'));
}
示例8: it_sets_cookies
/**
* @test
*/
public function it_sets_cookies()
{
$request = (new FigCookieTestingRequest())->withHeader(Cookies::COOKIE_HEADER, 'theme=light; sessionToken=RAPELCGRQ; hello=world');
$request = FigRequestCookies::set($request, Cookie::create('hello', 'WORLD!'));
$this->assertEquals('theme=light; sessionToken=RAPELCGRQ; hello=WORLD%21', $request->getHeaderLine('Cookie'));
}