Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Test proper configuration & functioning of sessions.
- *
- * If this blows up, sessions are not configured properly.
- * If this doesn't bloe up, but subsequent requests do not show session data,
- * then your save_path is probably incorrect.
- * Look for "permission denied" error messages.
- *
- * If no user data, and the session ID keeps changing, then sessions themselves
- * are not storing properly - probably a cookie issue.
- *
- * ------------------------------------------------------------------------
- */
- class Snoopy extends CI_Controller {
- function __construct() {
- parent::__construct();
- }
- function index() {
- echo '<pre>';
- $this->outer('Snoopy - Session Tester');
- // Are sessions loaded?
- if (isset($this->session))
- $this->out('Sessions are loaded');
- else {
- $this->out('Sessions are not loaded.');
- exit();
- }
- $this->out();
- // Show session metadata
- $this->outer('Session METADATA');
- $this->out('Session ID: ' . session_id());
- $this->out('IP address: ' . $_SERVER['REMOTE_ADDR']);
- $this->out('User agent: ' . $this->input->user_agent());
- $this->out();
- // Show session preferences
- $this->outer('Session PREFERENCES');
- $this->out('Session driver: ' . $this->config->item('sess_driver'));
- $this->out('Save path: ' . $this->config->item('sess_save_path'));
- $this->out('Cookie domain: ' . $this->config->item('cookie_domain'));
- $this->out('Cookie path: ' . $this->config->item('cookie_path'));
- $this->out('Cookie HTTPS only: ' . $this->config->item('cookie_secure'));
- $this->out();
- // Show all current session data
- $this->outer('Session USER DATA:');
- $stuff = $this->session->userdata();
- foreach ($stuff as $key => $value)
- $this->out($key . ' --> ' . $value);
- $this->out();
- // Set some session data for the next request
- $this->session->test1 = 'First test';
- $this->session->set_userdata('test2','Second test');
- $_SESSION['test3'] = 'Third test';
- }
- function out($message = '') {
- echo $message . '<br/>';
- }
- function outer($message = '') {
- echo $message . '<br/>';
- echo str_repeat('*', strlen($message)) . '<br/>';
- echo '<br/>';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement