Advertisement
Guest User

Untitled

a guest
Sep 15th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Test proper configuration & functioning of sessions.
  5.  *
  6.  * If this blows up, sessions are not configured properly.
  7.  * If this doesn't bloe up, but subsequent requests do not show session data,
  8.  * then your save_path is probably incorrect.
  9.  * Look for "permission denied" error messages.
  10.  *
  11.  * If no user data, and the session ID keeps changing, then sessions themselves
  12.  * are not storing properly - probably a cookie issue.
  13.  *
  14.  * ------------------------------------------------------------------------
  15.  */
  16. class Snoopy extends CI_Controller {
  17.  
  18.     function __construct() {
  19.         parent::__construct();
  20.     }
  21.  
  22.     function index() {
  23.         echo '<pre>';
  24.         $this->outer('Snoopy - Session Tester');
  25.        
  26.         // Are sessions loaded?
  27.         if (isset($this->session))
  28.             $this->out('Sessions are loaded');
  29.         else {
  30.             $this->out('Sessions are not loaded.');
  31.             exit();
  32.         }
  33.         $this->out();
  34.  
  35.         // Show session metadata
  36.         $this->outer('Session METADATA');
  37.         $this->out('Session ID: ' . session_id());
  38.         $this->out('IP address: ' . $_SERVER['REMOTE_ADDR']);
  39.         $this->out('User agent: ' . $this->input->user_agent());
  40.         $this->out();
  41.  
  42.         // Show session preferences
  43.         $this->outer('Session PREFERENCES');
  44.         $this->out('Session driver: ' . $this->config->item('sess_driver'));
  45.         $this->out('Save path: ' . $this->config->item('sess_save_path'));
  46.         $this->out('Cookie domain: ' . $this->config->item('cookie_domain'));
  47.         $this->out('Cookie path: ' . $this->config->item('cookie_path'));
  48.         $this->out('Cookie HTTPS only: ' . $this->config->item('cookie_secure'));
  49.         $this->out();
  50.  
  51.         // Show all current session data
  52.         $this->outer('Session USER DATA:');
  53.         $stuff = $this->session->userdata();
  54.         foreach ($stuff as $key => $value)
  55.             $this->out($key . ' --> ' . $value);
  56.         $this->out();
  57.        
  58.         // Set some session data for the next request
  59.         $this->session->test1 = 'First test';
  60.         $this->session->set_userdata('test2','Second test');
  61.         $_SESSION['test3'] = 'Third test';
  62.     }
  63.  
  64.     function out($message = '') {
  65.         echo $message . '<br/>';
  66.     }
  67.    
  68.     function outer($message = '') {
  69.         echo $message . '<br/>';
  70.         echo str_repeat('*',  strlen($message)) . '<br/>';
  71.         echo '<br/>';        
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement