CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.0 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.0
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Auth
    • Core
    • Error
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CakeSession
  • DataSource
  • DboSource

Interfaces

  • CakeSessionHandlerInterface
  1: <?php
  2: /**
  3:  * Session class for Cake.
  4:  *
  5:  * Cake abstracts the handling of sessions.
  6:  * There are several convenient methods to access session information.
  7:  * This class is the implementation of those methods.
  8:  * They are mostly used by the Session Component.
  9:  *
 10:  * PHP 5
 11:  *
 12:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 13:  * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 14:  *
 15:  * Licensed under The MIT License
 16:  * Redistributions of files must retain the above copyright notice.
 17:  *
 18:  * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 19:  * @link          http://cakephp.org CakePHP(tm) Project
 20:  * @package       Cake.Model.Datasource
 21:  * @since         CakePHP(tm) v .0.10.0.1222
 22:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 23:  */
 24: 
 25: App::uses('Set', 'Utility');
 26: App::uses('Security', 'Utility');
 27: 
 28: /**
 29:  * Session class for Cake.
 30:  *
 31:  * Cake abstracts the handling of sessions. There are several convenient methods to access session information.
 32:  * This class is the implementation of those methods. They are mostly used by the Session Component.
 33:  *
 34:  * @package       Cake.Model.Datasource
 35:  */
 36: class CakeSession {
 37: 
 38: /**
 39:  * True if the Session is still valid
 40:  *
 41:  * @var boolean
 42:  */
 43:     public static $valid = false;
 44: 
 45: /**
 46:  * Error messages for this session
 47:  *
 48:  * @var array
 49:  */
 50:     public static $error = false;
 51: 
 52: /**
 53:  * User agent string
 54:  *
 55:  * @var string
 56:  */
 57:     protected static $_userAgent = '';
 58: 
 59: /**
 60:  * Path to where the session is active.
 61:  *
 62:  * @var string
 63:  */
 64:     public static $path = '/';
 65: 
 66: /**
 67:  * Error number of last occurred error
 68:  *
 69:  * @var integer
 70:  */
 71:     public static $lastError = null;
 72: 
 73: /**
 74:  * 'Security.level' setting, "high", "medium", or "low".
 75:  *
 76:  * @var string
 77:  */
 78:     public static $security = null;
 79: 
 80: /**
 81:  * Start time for this session.
 82:  *
 83:  * @var integer
 84:  */
 85:     public static $time = false;
 86: 
 87: /**
 88:  * Cookie lifetime
 89:  *
 90:  * @var integer
 91:  */
 92:     public static $cookieLifeTime;
 93: 
 94: /**
 95:  * Time when this session becomes invalid.
 96:  *
 97:  * @var integer
 98:  */
 99:     public static $sessionTime = false;
100: 
101: /**
102:  * Current Session id
103:  *
104:  * @var string
105:  */
106:     public static $id = null;
107: 
108: /**
109:  * Hostname
110:  *
111:  * @var string
112:  */
113:     public static $host = null;
114: 
115: /**
116:  * Session timeout multiplier factor
117:  *
118:  * @var integer
119:  */
120:     public static $timeout = null;
121: 
122: /**
123:  * Number of requests that can occur during a session time without the session being renewed.
124:  * This feature is only used when config value `Session.autoRegenerate` is set to true.
125:  *
126:  * @var integer
127:  * @see CakeSession::_checkValid()
128:  */
129:     public static $requestCountdown = 10;
130: 
131: /**
132:  * Constructor.
133:  *
134:  * @param string $base The base path for the Session
135:  * @param boolean $start Should session be started right now
136:  * @return void
137:  */
138:     public static function init($base = null, $start = true) {
139:         self::$time = time();
140: 
141:         $checkAgent = Configure::read('Session.checkAgent');
142:         if (($checkAgent === true || $checkAgent === null) && env('HTTP_USER_AGENT') != null) {
143:             self::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
144:         }
145:         self::_setPath($base);
146:         self::_setHost(env('HTTP_HOST'));
147:     }
148: 
149: /**
150:  * Setup the Path variable
151:  *
152:  * @param string $base base path
153:  * @return void
154:  */
155:     protected static function _setPath($base = null) {
156:         if (empty($base)) {
157:             self::$path = '/';
158:             return;
159:         }
160:         if (strpos($base, 'index.php') !== false) {
161:              $base = str_replace('index.php', '', $base);
162:         }
163:         if (strpos($base, '?') !== false) {
164:              $base = str_replace('?', '', $base);
165:         }
166:         self::$path = $base;
167:     }
168: 
169: /**
170:  * Set the host name
171:  *
172:  * @param string $host Hostname
173:  * @return void
174:  */
175:     protected static function _setHost($host) {
176:         self::$host = $host;
177:         if (strpos(self::$host, ':') !== false) {
178:             self::$host = substr(self::$host, 0, strpos(self::$host, ':'));
179:         }
180:     }
181: 
182: /**
183:  * Starts the Session.
184:  *
185:  * @return boolean True if session was started
186:  */
187:     public static function start() {
188:         if (self::started()) {
189:             return true;
190:         }
191:         $id = self::id();
192:         session_write_close();
193:         self::_configureSession();
194:         self::_startSession();
195: 
196:         if (!$id && self::started()) {
197:             self::_checkValid();
198:         }
199: 
200:         self::$error = false;
201:         return self::started();
202:     }
203: 
204: /**
205:  * Determine if Session has been started.
206:  *
207:  * @return boolean True if session has been started.
208:  */
209:     public static function started() {
210:         return isset($_SESSION) && session_id();
211:     }
212: 
213: /**
214:  * Returns true if given variable is set in session.
215:  *
216:  * @param string $name Variable name to check for
217:  * @return boolean True if variable is there
218:  */
219:     public static function check($name = null) {
220:         if (!self::started() && !self::start()) {
221:             return false;
222:         }
223:         if (empty($name)) {
224:             return false;
225:         }
226:         $result = Set::classicExtract($_SESSION, $name);
227:         return isset($result);
228:     }
229: 
230: /**
231:  * Returns the Session id
232:  *
233:  * @param string $id
234:  * @return string Session id
235:  */
236:     public static function id($id = null) {
237:         if ($id) {
238:             self::$id = $id;
239:             session_id(self::$id);
240:         }
241:         if (self::started()) {
242:             return session_id();
243:         }
244:         return self::$id;
245:     }
246: 
247: /**
248:  * Removes a variable from session.
249:  *
250:  * @param string $name Session variable to remove
251:  * @return boolean Success
252:  */
253:     public static function delete($name) {
254:         if (self::check($name)) {
255:             self::_overwrite($_SESSION, Set::remove($_SESSION, $name));
256:             return (self::check($name) == false);
257:         }
258:         self::_setError(2, __d('cake_dev', "%s doesn't exist", $name));
259:         return false;
260:     }
261: 
262: /**
263:  * Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself
264:  *
265:  * @param array $old Set of old variables => values
266:  * @param array $new New set of variable => value
267:  * @return void
268:  */
269:     protected static function _overwrite(&$old, $new) {
270:         if (!empty($old)) {
271:             foreach ($old as $key => $var) {
272:                 if (!isset($new[$key])) {
273:                     unset($old[$key]);
274:                 }
275:             }
276:         }
277:         foreach ($new as $key => $var) {
278:             $old[$key] = $var;
279:         }
280:     }
281: 
282: /**
283:  * Return error description for given error number.
284:  *
285:  * @param integer $errorNumber Error to set
286:  * @return string Error as string
287:  */
288:     protected static function _error($errorNumber) {
289:         if (!is_array(self::$error) || !array_key_exists($errorNumber, self::$error)) {
290:             return false;
291:         } else {
292:             return self::$error[$errorNumber];
293:         }
294:     }
295: 
296: /**
297:  * Returns last occurred error as a string, if any.
298:  *
299:  * @return mixed Error description as a string, or false.
300:  */
301:     public static function error() {
302:         if (self::$lastError) {
303:             return self::_error(self::$lastError);
304:         }
305:         return false;
306:     }
307: 
308: /**
309:  * Returns true if session is valid.
310:  *
311:  * @return boolean Success
312:  */
313:     public static function valid() {
314:         if (self::read('Config')) {
315:             if (self::_validAgentAndTime() && self::$error === false) {
316:                 self::$valid = true;
317:             } else {
318:                 self::$valid = false;
319:                 self::_setError(1, 'Session Highjacking Attempted !!!');
320:             }
321:         }
322:         return self::$valid;
323:     }
324: 
325: /**
326:  * Tests that the user agent is valid and that the session hasn't 'timed out'.
327:  * Since timeouts are implemented in CakeSession it checks the current self::$time
328:  * against the time the session is set to expire.  The User agent is only checked
329:  * if Session.checkAgent == true.
330:  *
331:  * @return boolean
332:  */
333:     protected static function _validAgentAndTime() {
334:         $config = self::read('Config');
335:         $validAgent = (
336:             Configure::read('Session.checkAgent') === false ||
337:             self::$_userAgent == $config['userAgent']
338:         );
339:         return ($validAgent && self::$time <= $config['time']);
340:     }
341: 
342: /**
343:  * Get / Set the userAgent
344:  *
345:  * @param string $userAgent Set the userAgent
346:  * @return void
347:  */
348:     public static function userAgent($userAgent = null) {
349:         if ($userAgent) {
350:             self::$_userAgent = $userAgent;
351:         }
352:         return self::$_userAgent;
353:     }
354: 
355: /**
356:  * Returns given session variable, or all of them, if no parameters given.
357:  *
358:  * @param mixed $name The name of the session variable (or a path as sent to Set.extract)
359:  * @return mixed The value of the session variable
360:  */
361:     public static function read($name = null) {
362:         if (!self::started() && !self::start()) {
363:             return false;
364:         }
365:         if (is_null($name)) {
366:             return self::_returnSessionVars();
367:         }
368:         if (empty($name)) {
369:             return false;
370:         }
371:         $result = Set::classicExtract($_SESSION, $name);
372: 
373:         if (!is_null($result)) {
374:             return $result;
375:         }
376:         self::_setError(2, "$name doesn't exist");
377:         return null;
378:     }
379: 
380: /**
381:  * Returns all session variables.
382:  *
383:  * @return mixed Full $_SESSION array, or false on error.
384:  */
385:     protected static function _returnSessionVars() {
386:         if (!empty($_SESSION)) {
387:             return $_SESSION;
388:         }
389:         self::_setError(2, 'No Session vars set');
390:         return false;
391:     }
392: 
393: /**
394:  * Writes value to given session variable name.
395:  *
396:  * @param mixed $name Name of variable
397:  * @param string $value Value to write
398:  * @return boolean True if the write was successful, false if the write failed
399:  */
400:     public static function write($name, $value = null) {
401:         if (!self::started() && !self::start()) {
402:             return false;
403:         }
404:         if (empty($name)) {
405:             return false;
406:         }
407:         $write = $name;
408:         if (!is_array($name)) {
409:             $write = array($name => $value);
410:         }
411:         foreach ($write as $key => $val) {
412:             self::_overwrite($_SESSION, Set::insert($_SESSION, $key, $val));
413:             if (Set::classicExtract($_SESSION, $key) !== $val) {
414:                 return false;
415:             }
416:         }
417:         return true;
418:     }
419: 
420: /**
421:  * Helper method to destroy invalid sessions.
422:  *
423:  * @return void
424:  */
425:     public static function destroy() {
426:         if (self::started()) {
427:             session_destroy();
428:         }
429:         self::clear();
430:     }
431: 
432: /**
433:  * Clears the session, the session id, and renew's the session.
434:  *
435:  * @return void
436:  */
437:     public static function clear() {
438:         $_SESSION = null;
439:         self::$id = null;
440:         self::start();
441:         self::renew();
442:     }
443: 
444: /**
445:  * Helper method to initialize a session, based on Cake core settings.
446:  *
447:  * Sessions can be configured with a few shortcut names as well as have any number of ini settings declared.
448:  *
449:  * @return void
450:  * @throws CakeSessionException Throws exceptions when ini_set() fails.
451:  */
452:     protected static function _configureSession() {
453:         $sessionConfig = Configure::read('Session');
454:         $iniSet = function_exists('ini_set');
455: 
456:         if (isset($sessionConfig['defaults'])) {
457:             $defaults = self::_defaultConfig($sessionConfig['defaults']);
458:             if ($defaults) {
459:                 $sessionConfig = Set::merge($defaults, $sessionConfig);
460:             }
461:         }
462:         if (!isset($sessionConfig['ini']['session.cookie_secure']) && env('HTTPS')) {
463:             $sessionConfig['ini']['session.cookie_secure'] = 1;
464:         }
465:         if (isset($sessionConfig['timeout']) && !isset($sessionConfig['cookieTimeout'])) {
466:             $sessionConfig['cookieTimeout'] = $sessionConfig['timeout'];
467:         }
468:         if (!isset($sessionConfig['ini']['session.cookie_lifetime'])) {
469:             $sessionConfig['ini']['session.cookie_lifetime'] = $sessionConfig['cookieTimeout'] * 60;
470:         }
471:         if (!isset($sessionConfig['ini']['session.name'])) {
472:             $sessionConfig['ini']['session.name'] = $sessionConfig['cookie'];
473:         }
474:         if (!empty($sessionConfig['handler'])) {
475:             $sessionConfig['ini']['session.save_handler'] = 'user';
476:         }
477: 
478:         if (empty($_SESSION)) {
479:             if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
480:                 foreach ($sessionConfig['ini'] as $setting => $value) {
481:                     if (ini_set($setting, $value) === false) {
482:                         throw new CakeSessionException(sprintf(
483:                             __d('cake_dev', 'Unable to configure the session, setting %s failed.'),
484:                             $setting
485:                         ));
486:                     }
487:                 }
488:             }
489:         }
490:         if (!empty($sessionConfig['handler']) && !isset($sessionConfig['handler']['engine'])) {
491:             call_user_func_array('session_set_save_handler', $sessionConfig['handler']);
492:         }
493:         if (!empty($sessionConfig['handler']['engine'])) {
494:             $handler = self::_getHandler($sessionConfig['handler']['engine']);
495:             session_set_save_handler(
496:                 array($handler, 'open'),
497:                 array($handler, 'close'),
498:                 array($handler, 'read'),
499:                 array($handler, 'write'),
500:                 array($handler, 'destroy'),
501:                 array($handler, 'gc')
502:             );
503:         }
504:         Configure::write('Session', $sessionConfig);
505:         self::$sessionTime = self::$time + ($sessionConfig['timeout'] * 60);
506:     }
507: 
508: /**
509:  * Find the handler class and make sure it implements the correct interface.
510:  *
511:  * @param string $handler
512:  * @return void
513:  * @throws CakeSessionException
514:  */
515:     protected static function _getHandler($handler) {
516:         list($plugin, $class) = pluginSplit($handler, true);
517:         App::uses($class, $plugin . 'Model/Datasource/Session');
518:         if (!class_exists($class)) {
519:             throw new CakeSessionException(__d('cake_dev', 'Could not load %s to handle the session.', $class));
520:         }
521:         $handler = new $class();
522:         if ($handler instanceof CakeSessionHandlerInterface) {
523:             return $handler;
524:         }
525:         throw new CakeSessionException(__d('cake_dev', 'Chosen SessionHandler does not implement CakeSessionHandlerInterface it cannot be used with an engine key.'));
526:     }
527: 
528: /**
529:  * Get one of the prebaked default session configurations.
530:  *
531:  * @param string $name
532:  * @return boolean|array
533:  */
534:     protected static function _defaultConfig($name) {
535:         $defaults = array(
536:             'php' => array(
537:                 'cookie' => 'CAKEPHP',
538:                 'timeout' => 240,
539:                 'cookieTimeout' => 240,
540:                 'ini' => array(
541:                     'session.use_trans_sid' => 0,
542:                     'session.cookie_path' => self::$path
543:                 )
544:             ),
545:             'cake' => array(
546:                 'cookie' => 'CAKEPHP',
547:                 'timeout' => 240,
548:                 'cookieTimeout' => 240,
549:                 'ini' => array(
550:                     'session.use_trans_sid' => 0,
551:                     'url_rewriter.tags' => '',
552:                     'session.serialize_handler' => 'php',
553:                     'session.use_cookies' => 1,
554:                     'session.cookie_path' => self::$path,
555:                     'session.auto_start' => 0,
556:                     'session.save_path' => TMP . 'sessions',
557:                     'session.save_handler' => 'files'
558:                 )
559:             ),
560:             'cache' => array(
561:                 'cookie' => 'CAKEPHP',
562:                 'timeout' => 240,
563:                 'cookieTimeout' => 240,
564:                 'ini' => array(
565:                     'session.use_trans_sid' => 0,
566:                     'url_rewriter.tags' => '',
567:                     'session.auto_start' => 0,
568:                     'session.use_cookies' => 1,
569:                     'session.cookie_path' => self::$path,
570:                     'session.save_handler' => 'user',
571:                 ),
572:                 'handler' => array(
573:                     'engine' => 'CacheSession',
574:                     'config' => 'default'
575:                 )
576:             ),
577:             'database' => array(
578:                 'cookie' => 'CAKEPHP',
579:                 'timeout' => 240,
580:                 'cookieTimeout' => 240,
581:                 'ini' => array(
582:                     'session.use_trans_sid' => 0,
583:                     'url_rewriter.tags' => '',
584:                     'session.auto_start' => 0,
585:                     'session.use_cookies' => 1,
586:                     'session.cookie_path' => self::$path,
587:                     'session.save_handler' => 'user',
588:                     'session.serialize_handler' => 'php',
589:                 ),
590:                 'handler' => array(
591:                     'engine' => 'DatabaseSession',
592:                     'model' => 'Session'
593:                 )
594:             )
595:         );
596:         if (isset($defaults[$name])) {
597:             return $defaults[$name];
598:         }
599:         return false;
600:     }
601: 
602: /**
603:  * Helper method to start a session
604:  *
605:  * @return boolean Success
606:  */
607:     protected static function _startSession() {
608:         if (headers_sent()) {
609:             if (empty($_SESSION)) {
610:                 $_SESSION = array();
611:             }
612:         } elseif (!isset($_SESSION)) {
613:             session_cache_limiter ("must-revalidate");
614:             session_start();
615:             header ('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
616:         } else {
617:             session_start();
618:         }
619:         return true;
620:     }
621: 
622: /**
623:  * Helper method to create a new session.
624:  *
625:  * @return void
626:  */
627:     protected static function _checkValid() {
628:         if (!self::started() && !self::start()) {
629:             self::$valid = false;
630:             return false;
631:         }
632:         if ($config = self::read('Config')) {
633:             $sessionConfig = Configure::read('Session');
634: 
635:             if (self::_validAgentAndTime()) {
636:                 self::write('Config.time', self::$sessionTime);
637:                 if (isset($sessionConfig['autoRegenerate']) && $sessionConfig['autoRegenerate'] === true) {
638:                     $check = $config['countdown'];
639:                     $check -= 1;
640:                     self::write('Config.countdown', $check);
641: 
642:                     if ($check < 1) {
643:                         self::renew();
644:                         self::write('Config.countdown', self::$requestCountdown);
645:                     }
646:                 }
647:                 self::$valid = true;
648:             } else {
649:                 self::destroy();
650:                 self::$valid = false;
651:                 self::_setError(1, 'Session Highjacking Attempted !!!');
652:             }
653:         } else {
654:             self::write('Config.userAgent', self::$_userAgent);
655:             self::write('Config.time', self::$sessionTime);
656:             self::write('Config.countdown', self::$requestCountdown);
657:             self::$valid = true;
658:         }
659:     }
660: 
661: /**
662:  * Restarts this session.
663:  *
664:  * @return void
665:  */
666:     public static function renew() {
667:         if (session_id()) {
668:             if (session_id() != '' || isset($_COOKIE[session_name()])) {
669:                 setcookie(Configure::read('Session.cookie'), '', time() - 42000, self::$path);
670:             }
671:             session_regenerate_id(true);
672:         }
673:     }
674: 
675: /**
676:  * Helper method to set an internal error message.
677:  *
678:  * @param integer $errorNumber Number of the error
679:  * @param string $errorMessage Description of the error
680:  * @return void
681:  */
682:     protected static function _setError($errorNumber, $errorMessage) {
683:         if (self::$error === false) {
684:             self::$error = array();
685:         }
686:         self::$error[$errorNumber] = $errorMessage;
687:         self::$lastError = $errorNumber;
688:     }
689: }
690: 
691: 
692: /**
693:  * Interface for Session handlers.  Custom session handler classes should implement
694:  * this interface as it allows CakeSession know how to map methods to session_set_save_handler()
695:  *
696:  * @package       Cake.Model.Datasource
697:  */
698: interface CakeSessionHandlerInterface {
699: /**
700:  * Method called on open of a session.
701:  *
702:  * @return boolean Success
703:  */
704:     public function open();
705: 
706: /**
707:  * Method called on close of a session.
708:  *
709:  * @return boolean Success
710:  */
711:     public function close();
712: 
713: /**
714:  * Method used to read from a session.
715:  *
716:  * @param mixed $id The key of the value to read
717:  * @return mixed The value of the key or false if it does not exist
718:  */
719:     public function read($id);
720: 
721: /**
722:  * Helper function called on write for sessions.
723:  *
724:  * @param integer $id ID that uniquely identifies session in database
725:  * @param mixed $data The value of the data to be saved.
726:  * @return boolean True for successful write, false otherwise.
727:  */
728:     public function write($id, $data);
729: 
730: /**
731:  * Method called on the destruction of a session.
732:  *
733:  * @param integer $id ID that uniquely identifies session in database
734:  * @return boolean True for successful delete, false otherwise.
735:  */
736:     public function destroy($id);
737: 
738: /**
739:  * Run the Garbage collection on the session storage.  This method should vacuum all
740:  * expired or dead sessions.
741:  *
742:  * @param integer $expires Timestamp (defaults to current time)
743:  * @return boolean Success
744:  */
745:     public function gc($expires = null);
746: }
747: 
748: 
749: // Initialize the session
750: CakeSession::init();
751: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs