本文整理汇总了PHP中Cookie::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::setName方法的具体用法?PHP Cookie::setName怎么用?PHP Cookie::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie::setName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Cookie
/**
* Creates a cookie object, adds it to the cookies stack and returns an reference to this cookie
*
* @param string $name
* Name of cookie to create
*
* @return \Core\Http\Cookie\CookieInterface
*/
public function &createCookie(string $name)
{
$cookie = new Cookie();
$cookie->setName($name);
$this->addCookie($cookie);
return $cookie;
}
示例2: 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;
}
示例3: setCookie
public static function setCookie($user, $name, $value, $expires)
{
//self::cleanCookies();
$cookie = self::getCookieObject($user, $name);
if ($cookie) {
$cookie->setValue($value);
$cookie->setExpires(date("Y-m-d H:i:s", $expires));
$cookie->save();
} else {
$cookie = new Cookie();
$cookie->setUserId($user->getId());
$cookie->setName($name);
$cookie->setValue($value);
$cookie->setExpires(date("Y-m-d H:i:s", $expires));
$cookie->save();
}
}